标签:des style blog http io ar color os 使用
这是我从网上(http://www.open-open.com/lib/view/open1393488232380.html)找到的一个使用Numpy和matplotlib的示例程序,我用这段代码来测试Numpy和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()
在Windows上安装Numpy和matplotlib是一个和痛苦的过程。总体来说,安装这两个包的官方安装程序是远远不够的。总会提示你缺这个缺那个。我的解决办法接单粗暴,提示缺少什么了我就谷歌然后安装这个包。所有的包都可以从这个网站(http://www.lfd.uci.edu/~gohlke/pythonlibs/)找得到。
最后为了安装Nump和matplotlib,我一共安装了6个包:
相比在Windows上安装软件,在Ubuntu上安装就简单多了,一句命令搞定:
1: sudo apt-get install python-numpy python-matplotlib
所有依赖的包都自动安装上了,给个赞!
真心说一句,Ubuntu除了网络问题不给力之外,装软件真心是很赞的!
标签:des style blog http io ar color os 使用
原文地址:http://www.cnblogs.com/NO-30/p/4149391.html