网上许多matplotlib的安装教程都是比较复杂,需要配置许多环境,对于电脑基础不好的人来说可是一件头疼的事情,今天我介绍一个简单的安装方法。

1.Win+R输入cmd进入到CMD窗口下,执行python -m pip install -U pip setuptools进行升级。

http://qn.javajgs.com/20220621/98e15183-c258-4c86-aa90-ff68c7c847652022062183b9b8c2-14c5-418a-ab84-418a5df917511.jpg?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p6eDIwMTZ6eng=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

2.输入python -m pip install matplotlib进行自动的安装,系统会自动下载安装包

http://qn.javajgs.com/20220621/b0ce51e5-70af-47ea-991b-75cc55972956202206210916c3d1-3407-47fd-bf61-875da2d88cad1.jpg?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p6eDIwMTZ6eng=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

 

3.进入到python idle中,运行import matplotlib,如下图所示,如果没有报错,就证明安装成果。

http://qn.javajgs.com/20220621/0ad1bff3-a8ac-49d5-89e1-505a263ba03220220621f0c9b20d-2831-45d9-b1c9-9b9d004b80d31.jpg?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p6eDIwMTZ6eng=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

 

输入以下代码运行成果证明安装没问题

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()

http://qn.javajgs.com/20220621/aec6d1bb-83d1-4055-87a6-df7ab70fc720202206212d7ff312-b740-4ed5-96cd-b4aea84a4eab1.jpg?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p6eDIwMTZ6eng=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

 

来源:https://blog.csdn.net/zzx2016zzx/article/details/83099583