本文簡單介紹了Python繪圖庫Matplotlib的安裝,簡介如下:
matplotlib是python最著名的繪圖庫,它提供了一整套和matlab相似的命令API,十分適合交互式地
進行制圖。Matplotlib的安裝可以參見:官網鏈接 http://matplotlib.org/users/installing.html
安裝總結步驟如下:
windows 平臺上下載.exe格式 直接安裝。
1.python下載安裝 下載地址:http://www.python.org/download/。
2.安裝你所需要版本(這個要根據步驟1的python版本)的Matplotlib,下載地址:http://matplotlib.org/downloads.html。
下面安裝Matplotlib 依賴的庫
3.對于標準版的Python來說,要使用Matplotlib,還需要安裝numpy模塊,其下載地址為:http://sourceforge.net/projects/numpy/files/NumPy/。
4.msvcp71.dll, 在某些系統上,你可能還需要下載msvcp71.dll庫。下載地址:http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71
下載解壓后把它拖到c:\windows\system32目錄中。
5.運行一個簡單的程序例子:
view plaincopy在CODE上查看代碼片派生到我的代碼片
1
2
3
4
|
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,你可以到這里下載安裝:http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil。
把dateutil 安裝完后又出現如下錯誤:
raise ImportError("matplotlib requires pyparsing")
ImportError: matplotlib requires pyparsing
需要 pyparsing 到這里下載安裝:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing。
完成以上步驟,運行上面的例子就可以顯示我們的圖像,如下所示。
在程序安裝過程中如果遇到需要安裝的一些依賴包,你可以到這里查找http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing,這確實是個好資源。
可以根據所畫圖形的需要 在下面的鏈接里選擇相應的圖形 進行修改,繪出自己所需的圖像。
example: http://matplotlib.org/examples/index.html, gallery:http://matplotlib.org/gallery.html
相關資源鏈接:
Matplotlib Tutorial 中文翻譯的 http://reverland.org/python/2012/09/07/matplotlib-tutorial/ 。
用Python做科學計算 http://sebug.net/paper/books/scipydoc/index.html 。
資源下載:
如果上面不能下載。我把安裝 python matplotlib所需的軟件放到百度網盤了,可以到這里這下:http://pan.baidu.com/s/1i3C99rv。
中文亂碼解決方法
注意繪圖時中文的解決方法, 在.py文件頭部加上如下內容:
1
2
3
4
|
# -*- coding: utf-8 -*- from pylab import * mpl.rcParams[ 'font.sans-serif' ] = [ 'SimHei' ] #指定默認字體 mpl.rcParams[ 'axes.unicode_minus' ] = False #解決保存圖像是負號'-'顯示為方塊的問題 |
繪圖腳本.py轉為 .exe
如果為希望能把Python腳本發布為脫離Python平臺運行的可執行程序,比如單個的exe文件。可以參考這篇博文:http://blog.csdn.net/daniel_ustc/article/details/15501385
使用便攜式的Python環境
Python 編程語言在移動設備下的運行環境和編程語言環境,便攜式的Python是一個Python的編程語言預先從任何USB存儲設備直接運行,使在任何時候,你有一臺便攜式的編程環境。使其起來挺方便的,推薦使用。