2012-11-27 28 views
4

當使用兩個選項histt​​ype ='stepfilled'和log = True時,我有一個問題在matplotlib中顯示直方圖。我在matplotlib 1.1.0版本中遇到了這個問題,發現它仍然存在於1.2.0版本中。matplotlib在y日誌規模stepfilled直方圖不能正確顯示

不幸的是,我沒有張貼圖片的權利,但你可以用這個簡單的代碼檢查出這種行爲:

import numpy as np 
import matplotlib as mpl 
import matplotlib.pyplot as plt 

mu, sigma = 200, 25 
x = mu + sigma*np.random.randn(10000) 
n, bins, patches = plt.hist(x, 50, normed=1, histtype='bar',log=True) 
plt.savefig("test1.png") 
plt.clf() 
n, bins, patches = plt.hist(x, 50, normed=1, histtype='stepfilled',log=True) 
plt.savefig("test2.png") 

第一張圖正確地顯示,而在第二種情況下,與選項histt​​ype ='stepfilled'而不是'bar',不。有人有什麼線索嗎?

回答

1

這是matplotlib中的一個開放的bug。也許你可以模擬stepfilled操作第一個圖形中的條形樣式。

GitHub上的問題:

+1

有關信息,錯誤已在2013年1月得到糾正,並且在您鏈接的問題中提供了一個工作修復程序。 –

+0

感謝您的更新! –

1

如果使用

plt.hist(x, 50, normed=1, histtype='stepfilled') 
plt.semilogy() 

你得到預期的結果,需要提醒的是,它看起來怪異與零個值箱。