matplotlib 是python最著名的繪圖庫,它提供了一整套和matlab相似的命令API,十分適合交互式地進行制圖。而且也可以方便地將它作為繪圖控件,嵌入GUI應用程序中。它的文檔相當完備,並且 Gallery頁面 中有上百幅縮略圖,打開之后都有源程序。因此如果你需要繪制某種類型的圖,只需要在這個頁面中瀏覽、復制、粘貼一下,基本上都能搞定。
安裝
參考 http://blog.csdn.net/daniel_ustc/article/details/9714163
官網
http://matplotlib.org/1.2.1/index.html
注意其中的examples
案例
1. 柱狀圖
參考http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html
2. 餅形圖
#! coding: cp936 from pylab import * # make a square figure and axes figure(1, figsize=(6,6)) ax = axes([0.1, 0.1, 0.8, 0.8]) fracs = [45, 30, 25] #每一塊占得比例,總和為100 explode=(0, 0, 0.08) #離開整體的距離,看效果 labels = 'Hogs', 'Dogs', 'Logs' #對應每一塊的標志 pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90, colors = ("g", "r", "y")) # startangle是開始的角度,默認為0,從這里開始按逆時針方向依次展開 title('Raining Hogs and Dogs') #標題 show()
效果