#关于python安装matplotlib的一些问题解决办法
python要实现数据可视化需要借助一些“库”
对各种可引用的库的说明可见 https://blog.csdn.net/weixin_39777626/article/details/78598346
matplotlib则是其中一个可实现2维可视化图形的一个图库。
matplotlib安装步骤
1、先检测python环境,可在系统高级设置中的path里查看有无python。
在windows powershell 或cmd下输入python 检测是否成功执行。
2、在Windows powershell 或cmd 下执行命令下载安装matplotlib
详情可见 https://blog.csdn.net/qq_41720475/article/details/81978694
注意:在下载matplotlib之前会给pip升级,大部分人会遇到一个问题,
可参考这个博客解决
https://blog.csdn.net/laofashi2015/article/details/88689871
如果还是有问题,可以尝试加镜像,因为下载是从外网下的,会有网速问题。
可输入命令
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple(未分行,一排)
//可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。
3、安装成功后
打开pythonIDLE 输入 import matplotlib 无报错即可
输入代码(一行一行输入,整体输入会报错)
import matplotlib.pyplot as plt
labels=‘frogs’,‘hogs’,‘dogs’,‘logs’
sizes=15,20,45,10
colors=‘yellowgreen’,‘gold’,‘lightskyblue’,‘lightcoral’
explode=0,0.1,0,0
plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct=’%1.1f%%’,shadow=True,startangle=50)
plt.axis(‘equal’)
plt.show()
得到图形
即为下载完成