【问题标题】:Matplotlib horizontal histogram: Bins with low values disappearMatplotlib 水平直方图:低值的 bin 消失
【发布时间】:2018-09-22 23:39:15
【问题描述】:

当我使用 matplotlib 的 hist 函数以水平方向绘制直方图时,会发生以下情况:有时,在默认方向上存在的具有非常低值的 bin 不会显示为水平方向。

在笔记本单元格中执行以下代码(遗憾的是,我无法上传/应该生成两个直方图,您可以在其中看到分布的最多右/左箱的差异。默认情况下,在 ~3 和 -3 处有小箱,水平方向不存在。

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(20)
y = np.random.normal(size=1000000)
plt.hist(y, bins=20)
plt.show()
plt.hist(y, bins=20, orientation='horizontal')
plt.show()

我还在这里链接了这些情节:

default - horizontal

有人知道这里有什么问题吗?

【问题讨论】:

  • 你的 matplotlib 版本是多少?
  • 我无法重现您的问题。 3、-3处的步骤在这里是visible in both plots.matplotlib2.2
  • 图像看起来好像被裁剪了。你能让代码和图像保持一致吗?此代码生成的图像是什么? (它们应该有轴和标签之类的东西。)

标签: python matplotlib histogram


【解决方案1】:

matplotlib 的 hist 函数也有类似的问题。可悲的是,我恢复到手动使用 barh 和 numpy.histogram() 。

您的代码可能如下所示:

y = np.random.normal(size=1000000)
yhist = np.histogram(y, bins=20)
plt.barh(y=yhist[1][:20], x=yhist[0])
plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 2013-04-03
    • 2016-10-14
    • 2011-10-22
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多