问题描述
当同时使用histtype ='stepfilled'和log = True时,我在matplotlib中显示直方图时遇到问题.我在matplotlib 1.1.0版中遇到了这个问题,发现在1.2.0版中仍然存在.
I have a problem displaying histograms in matplotlib when both options histtype='stepfilled' and log=True are used. I had this problem in matplotlib version 1.1.0 and found that this is still present in version 1.2.0.
不幸的是,我没有发布图像的权利,但是您可以使用以下简单代码来检查这种行为:
Unfortunately I don't have the rights to post images, but you can check out this behaviour with this simple code:
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")
第一个数字正确显示,而在第二种情况下,选项histtype ='stepfilled'而不是'bar',否.有人有任何线索吗?
The first figure shows correctly, whereas in the second case, with the option histtype='stepfilled' instead of 'bar', no.Somebody has any clue?
推荐答案
如果使用
plt.hist(x, 50, normed=1, histtype='stepfilled')
plt.semilogy()
您会得到预期的结果,但要注意的是,对于零值的垃圾箱,它看起来很奇怪.
you get the expected result, with the caveat that it looks weird for bins with zero values.
这篇关于matplotlib y刻度的逐步填充历史记录无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!