matplotlib:使用matplotlib繪製圖表,matplotlib繪製

來源:互聯網
上載者:User

matplotlib:使用matplotlib繪製圖表,matplotlib繪製
http://blog.csdn.net/pipisorry/article/details/39123171

matplotlib下載及API手冊地址:http://sourceforge.net/projects/matplotlib/files/matplotlib/

數學庫numpy下載及API手冊地址:http://www.scipy.org/Download

matplotlib的官網是: http://matplotlib.org/  官網有豐富的圖例和文檔說明。

matplotlib在github的地址為:https://github.com/matplotlib 


幾個繪圖的例子【來自API手冊】

1、最簡單的圖:

代碼:

#!/usr/bin/env pythonimport matplotlib.pyplot as pltplt.plot([10, 20, 30])plt.xlabel('tiems')plt.ylabel('numbers')plt.show()

測試:

2.餅圖:

代碼:

#!/usr/bin/env python# -*- coding: utf-8 -*-from pylab import *# make a square figure and axesfigure(1, figsize=(6,6))ax = axes([0.1, 0.1, 0.8, 0.8])labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'fracs = [15,30,45, 10]explode=(0, 0.05, 0, 0)pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})savefig('D:\\pie.png')show()

測試:

 

3、使用numpy庫函數:

代碼:

#!/usr/bin/env python# -*- coding: utf-8 -*-import numpy as npimport matplotlib.pyplot as pltt = np.arange(0.0, 1.01, 0.01)s = np.sin(2*2*np.pi*t)plt.fill(t, s*np.exp(-5*t), 'r')plt.grid(True)#儲存為PDF格式,也可儲存為PNG等圖形格式plt.savefig('D:\\test.pdf')plt.show()

測試:

 

from:http://blog.csdn.net/pipisorry/article/details/39123171ref:python使用matplotlib繪圖詳解-bar橫條圖
Python:使用matplotlib繪製圖表


怎用python的matplotlib模組畫累積分布圖

下面的程式繪製隨機變數X的累積分布函數和數組p的累加結果
>>> pl.plot(t, X.cdf(t))
>>> pl.plot(t2, np.add.accumulate(p)*(t2[1]-t2[0]))
 
使用python中的matplotlib 畫圖,怎關閉視窗?

plt.show() 好像只能這樣,只有你關閉了才往下執行
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.