可视化-vscode安装matplotlib工具


 

可视化工具中,最流行的工具之一是 Matplotlib,它是一个数学绘图库,可以制作简单的图表,如折线图和散点图;

使用pip可以安装Matplotlib;

安装步骤::

1、在vscode的终端输入命令: py -m pip install –upgrade pip   # 先更新pip版本

PS D:/01VSCodeScript/Python> python.exe -m pip install --upgrade pip
Requirement already satisfied: pip in c:/users/12593/appdata/local/programs/python/python310/lib/site-packages (22.0.4)
Collecting pip
  Downloading pip-22.1.2-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 64.1 kB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
      Successfully uninstalled pip-22.0.4
Successfully installed pip-22.1.2
PS D:/01VSCodeScript/Python> 

2、安装matplotlib;

PS D:/01VSCodeScript/Python> python -m pip install --user matplotlib
Collecting matplotlib
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken 
by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000283BF956350>, 'Connection to files.pythonhosted.org timed out.
(connect timeout=15)')': /packages/67/4e/5959c5822f0694e4c2beb93f9ee34b8ec49052fc79d88f8842d9ded72f02/matplotlib-3.5.2-cp310-cp310-win_amd64.whl Downloading matplotlib-3.5.2-cp310-cp310-win_amd64.whl (7.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.2/7.2 MB 304.0 kB/s eta 0:00:00 Collecting numpy>=1.17 Downloading numpy-1.23.0-cp310-cp310-win_amd64.whl (14.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.6/14.6 MB 2.3 MB/s eta 0:00:00 Collecting fonttools>=4.22.0 Downloading fonttools-4.33.3-py3-none-any.whl (930 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 930.9/930.9 kB 3.9 MB/s eta 0:00:00 Collecting cycler>=0.10 Downloading cycler-0.11.0-py3-none-any.whl (6.4 kB) Collecting pyparsing>=2.2.1 Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.3/98.3 kB 5.5 MB/s eta 0:00:00 Collecting kiwisolver>=1.0.1 Downloading kiwisolver-1.4.3-cp310-cp310-win_amd64.whl (55 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.3/55.3 kB 2.8 MB/s eta 0:00:00 Collecting pillow>=6.2.0 Downloading Pillow-9.2.0-cp310-cp310-win_amd64.whl (3.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 2.5 MB/s eta 0:00:00 Collecting python-dateutil>=2.7 Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 2.5 MB/s eta 0:00:00 Collecting packaging>=20.0 Downloading packaging-21.3-py3-none-any.whl (40 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.8/40.8 kB 984.2 kB/s eta 0:00:00 Collecting six>=1.5 Downloading six-1.16.0-py2.py3-none-any.whl (11 kB) Installing collected packages: six, pyparsing, pillow, numpy, kiwisolver, fonttools, cycler, python-dateutil, packaging, matplotlib WARNING: The script f2py.exe is installed in 'C:/Users/12593/AppData/Roaming/Python/Python310/Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts fonttools.exe, pyftmerge.exe, pyftsubset.exe and ttx.exe are installed in 'C:/Users/12593/AppData/Roaming/Python/Python310/Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed cycler-0.11.0 fonttools-4.33.3 kiwisolver-1.4.3 matplotlib-3.5.2 numpy-1.23.0 packaging-21.3 pillow-9.2.0 pyparsing-3.0.9 python-dateutil-2.8.2 six-1.16.0 PS D:/01VSCodeScript/Python>

3、检查路径

因为出现告警:

Import "matplotlib.pyplot" could not be resolved from source

可能是路径不对,

查看安装的模块;

PS D:/01VSCodeScript/Python> pip list
Package         Version
--------------- -------
autopep8        1.6.0  
cycler          0.11.0 
fonttools       4.33.3 
kiwisolver      1.4.3
matplotlib      3.5.2
numpy           1.23.0
packaging       21.3
Pillow          9.2.0
pip             22.1.2
pycodestyle     2.8.0
pygame          2.1.2
pyparsing       3.0.9
python-dateutil 2.8.2
setuptools      58.1.0
six             1.16.0
toml            0.10.2
PS D:/01VSCodeScript/Python> 

 

在终端中输入,检查路径

PS D:/01VSCodeScript/Python> pip show matplotlib
Name: matplotlib
Version: 3.5.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: c:/users/12593/appdata/roaming/python/python310/site-packages
Requires: cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by:
PS D:/01VSCodeScript/Python> 

 在搜索中输入:python.analysis.extraPaths

可视化-vscode安装matplotlib工具

 重新运行后,没有出现告警了

4、简单测试,python脚本:

 

import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
# 调用函数subplots,在一张图片中绘制一个或多个图表;
# fig,表示整张图片
# ax,表示图片中的各个图表
fig, ax = plt.subplots()
# 调用plot()方法,尝试根据给定的数据以有意义的方式绘制图表
ax.plot(squares)
# 函数plt.show(),打开Matplotlib查看并显示绘制的图表
plt.show()

  显示结果:

可视化-vscode安装matplotlib工具

 

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/272997.html

(0)
上一篇 2022年7月9日
下一篇 2022年7月9日

相关推荐

发表回复

登录后才能评论