2013-06-21 28 views
11

所有matplotlib exampleshist()生成一個數據集,自動提供數據設置到hist功能與一些二進制位(可能非均勻地間隔開)和功能計算並繪製直方圖。直方圖這是已經裝倉,我有倉和頻率值

我已經有直方圖數據,我只是想繪製它,我該怎麼做?!例如,我有垃圾箱(半開放範圍由廣場和彎曲托架符號表示),

[0, 1) 0 
[1, 2) 3 
[2, 3) 8 
[3, 4) 6 
[4, 5) 2 
[5, 6) 3 
[6, 7) 1 
[7, 8) 0 
+1

你想'酒吧'http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.bar – tacaswell

回答

7

或許重量參數將是你的問題的幫助。

import matplotlib.pyplot as plt 

a= [1,2,3,4,5,6,7,8,9] 
b= [5,3,4,5,3,2,1,2,3] 
plt.hist(a,9, weights=b) 
plt.show() 

或者,正如tcaswell所說,您可以創建一個條形圖並更改x軸。

Using matplotlib how could I plot a histogram with given data in python

是一個鏈接。

+0

我做了一個編輯。該代碼爲我工作。 –

+0

感謝您的幫助。 –