matplotlib的y轴对数坐标下使用stepfilled hist不能正确显示

4

当使用histtype='stepfilled'和log=True选项时,我在matplotlib中显示直方图遇到了问题。 我在matplotlib版本1.1.0中遇到了这个问题,并发现在版本1.2.0中仍然存在。

不幸的是,我没有发布图像的权利,但您可以使用此简单代码检查此行为:

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',则无法显示。 有人知道原因吗?
2个回答

1

如果您使用

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

您将获得预期的结果,但有一个注意事项,即对于值为零的箱子,它看起来很奇怪。


1

1
请注意,该问题已在2013年1月得到修正,并且您提供的链接中已经提供了可行的解决方案。 - Joël

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接