python新手安装matplotlib等第三方库

本人是python新手,在学习过程中遇到需要安装matplotlib,但是折腾了好久,无论是pip安装,还是官网下载(没网速),最后通过其他方法一次性安装成功,现在推荐给各位同为初学者的朋友。

1.下载Anaconda
官网下载地址:https://www.anaconda.com/download/
只需要选择合适的版本就好,以python版本为准,python是32位就下载32位的。

2.安装
没什么好说的,更改安装位置,然后等待就好,可能时间会比较长
注意,不要跳过任何安装步骤,如果什么东西安装失败,点击重试就好了。
如果你和我一样是小白的话,大神另说。

3.安装成功
安装结束之后就可以进行测试了

4.测试
以matplotlib为例,打开IDLE,输入import matplotlib
如果没有错误提示就OK

5.代码
搬运别人的

import numpy as np
import matplotlib.pyplot as plt

N = 5
menMeans = (20, 35, 30, 35, 27)
menStd =   (2, 3, 4, 1, 2)

ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)

womenMeans = (25, 32, 34, 20, 25)
womenStd =   (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)

# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )

ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )

def autolabel(rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
                ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)
plt.show()

运行效果如下
运行效果

猜你喜欢

转载自blog.csdn.net/weixin_40624269/article/details/81532234
今日推荐