我是W10 32位的python3.5版本,由于刚开始学习机器学习这一部分,需要用Matplotlib创建一些图。现在简单讲一下安装步骤
在这里先要确认你的电脑安装了pip
打开一个终端窗口,输入
<span style="font-size:18px;">$ python -m pip --version</span>此时如果输出pip版本,则可以进行下一步了;不然先要安装pip哦
<span style="font-size:18px;">$ python get-pip.py</span>而且我是已经安好了numpy 1.11.2函数库,简单提一下导入numpy的代码
>>> from numpy import *大家安装的时候都要注意下载和自己python版本对应的库啊,不然安装时会出问题的。
接下来就是下载Matplotlib啦,网址:https://sourceforge.net/projects/matplotlib/files/?source=typ_redirect
注意要把它安装在Python\Python35-32\Lib\site-packages\目录下,
在cmd输入安装matplotlib的代码并检测:
>>>python -m pip install matplotlib>>>import matplotlib好啦,以上就是简单安装步骤啦,下面我们简单用一下这个库
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()
如果一切顺利,就可以看到输出结果如下:
END
版权声明:本文为sinat_20350479原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。