2017-02-12 126 views
1

使用該代碼的關係,無法獲得條形圖中matplotlib

x = [420.0, 4353.0, 4373.0]; y = [269.0, 252.0, 283.0] 
plt.bar(x,y) 
plt.show() 

我得到:

Empty bar graph

哪裏吧?我如何讓他們出現?

回答

2

默認情況下,每個條形圖的寬度爲0.8,並且由於您的圖上x值的範圍很大,所以在渲染時該條幅太窄而不可見。你會想,而不是使用width kwarg

plt.bar(x, y, width=20) 

enter image description here 你的也使用數組來指定一個更大的寬度爲width值指定不同的寬度各條

plt.bar(x, y, width=[3000, 20, 20])