您的位置:首页 > 编程语言 > Python开发

使用 python Matplotlib 库绘图

2013-08-05 15:42 1071 查看
 

 

 Matplotlib的安装可以参见 官网链接 http://matplotlib.org/users/installing.html

下面总结步骤如下:

windows 平台上 下载.exe格式 直接安装。

1,python下载安装 下载地址

2,安装你所需要版本(这个要根据步骤1的python版本)的Matplotlib,下载地址

下面安装Matplotlib 依赖的库

3, 对于标准版的Python来说,要使用Matplotlib,还需要安装numpy模块,其下载地址

4, msvcp71.dll, 在某些系统上,你可能还需要下载msvcp71.dll库。下载

     这个档案,解压后把它拖到c:\windows\system32目录中。

5, 运行一个简单的程序例子:

 

[python]
view plaincopyprint?

import matplotlib.pyplot as plt  
plt.plot([1,2,3])  
plt.ylabel('some numbers')  
plt.show()  

import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.ylabel('some numbers')
plt.show()


发现出现了下面的错误:

raise ImportError("matplotlib requires dateutil")

ImportError: matplotlib requires dateutil

这个需要dateutil,你可以到这里下载安装。

把dateutil 安装完后又出现如下错误:

raise ImportError("matplotlib requires pyparsing")

ImportError: matplotlib requires pyparsing

需要 pyparsing  到这里下载安装。

完成以上步骤,运行上面的例子就可以显示我们的图像,如下所示。



在程序安装过程中如果遇到需要安装的一些依赖包,你可以到这里查找,确实是个好资源。

可以根据所画图形的需要 在下面的链接里选择相应的图形 进行修改,绘出自己所需的图像。

example: http://matplotlib.org/examples/index.html,  gallery:http://matplotlib.org/gallery.html

注意绘图时中文的解决方法, 在.py文件头部加上如下内容:

# -*- coding: utf-8 -*-   

from pylab import *  

mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体  

mpl.rcParams['axes.unicode_minus'] = False #解决保存图像是负号'-'显示为方块的问题  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: