首页 > 代码库 > 使用matplotlib在python中画图

使用matplotlib在python中画图

一、安装

此处以Ubuntu12.04为例:

$ sudo apt-get install ipython python-matplotlib python-numpy

二、简单实例

>>> plt.figure(1)                              # 创建图表1<matplotlib.figure.Figure object at 0x26fda10>>>> plt.figure(2)                              # 创建图表2<matplotlib.figure.Figure object at 0x2a5f610>>>> ax1 = plt.subplot(211)                     # 在图表2中创建子图1>>> ax2 = plt.subplot(212)                     # 在图表2中创建子图2>>> x = np.linspace(0, 3, 100)>>> plt.figure(1)                              # 选择图表1<matplotlib.figure.Figure object at 0x26fda10>>>> plt.plot(x, np.exp(x/3))[<matplotlib.lines.Line2D object at 0x36383d0>]>>> plt.sca(ax1)                               # 选择图表2的子图1>>> plt.plot(x, np.sin(x))[<matplotlib.lines.Line2D object at 0x3638890>]>>> plt.sca(ax2)                               # 选择图表2的子图2>>> plt.plot(x, np.sin(2*x))[<matplotlib.lines.Line2D object at 0x3638dd0>]>>> plt.show()

三、画MDCT正反变化图

四、参考

http://www.cnblogs.com/wei-li/archive/2012/05/23/2506940.html