首页 > 代码库 > 安装Numpy和matplotlib

安装Numpy和matplotlib

(1)测试程序

    这是我从网上(http://www.open-open.com/lib/view/open1393488232380.html)找到的一个使用Numpy和matplotlib的示例程序,我用这段代码来测试Numpy和matplotlib安装是否成功。

import numpy as npimport matplotlib.pyplot as plt N = 5menMeans = (20, 35, 30, 35, 27)menStd =   (2, 3, 4, 1, 2) ind = np.arange(N)  # the x locations for the groupswidth = 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 someax.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()

(2)在Windows上安装

    在Windows上安装Numpy和matplotlib是一个和痛苦的过程。总体来说,安装这两个包的官方安装程序是远远不够的。总会提示你缺这个缺那个。我的解决办法接单粗暴,提示缺少什么了我就谷歌然后安装这个包。所有的包都可以从这个网站(http://www.lfd.uci.edu/~gohlke/pythonlibs/)找得到。

     最后为了安装Nump和matplotlib,我一共安装了6个包:

  • matplotlib-1.4.2.win-amd64-py2.7
  • numpy-MKL-1.9.1.win-amd64-py2.7
  • pyparsing-2.0.3.win-amd64-py2.7
  • python-dateutil-2.2.win-amd64-py2.7
  • scipy-0.15.0b1.win-amd64-py2.7
  • six-1.8.0.win-amd64-py2.7

(3)在Ubuntu上安装

    相比在Windows上安装软件,在Ubuntu上安装就简单多了,一句命令搞定:

   1: sudo apt-get install python-numpy python-matplotlib

    所有依赖的包都自动安装上了,给个赞!

    真心说一句,Ubuntu除了网络问题不给力之外,装软件真心是很赞的!

安装Numpy和matplotlib