【问题标题】:matplotlib stepfilled hist in y-log scale don't show correctlyy-log 比例中的 matplotlib stepfilled hist 无法正确显示
【发布时间】:2012-11-27 11:40:07
【问题描述】:

当同时使用选项 histt​​ype='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")

第一个图正确显示,而在第二种情况下,使用选项 histt​​ype='stepfilled' 而不是 'bar',没有。 有人知道吗?

【问题讨论】:

    标签: matplotlib histogram


    【解决方案1】:

    这是 matplotlib 中的一个开放错误。也许您可以模拟stepfilled 操纵第一个图形中的条形样式。

    github上的问题:

    【讨论】:

    • 有关信息,错误已在 2013 年 1 月得到纠正,并且在您链接的问题中提供了有效的修复程序。
    【解决方案2】:

    如果你使用

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

    您会得到预期的结果,但需要注意的是,零值的 bin 看起来很奇怪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-28
      • 2023-01-18
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 2022-09-25
      • 2020-05-27
      • 2020-01-14
      相关资源
      最近更新 更多