Python Matplotlib水平直方图:具有低值的箱子消失

Python Matplotlib水平直方图:具有低值的箱子消失,python,matplotlib,histogram,Python,Matplotlib,Histogram,当我使用matplotlib的hist函数以水平方向绘制直方图时,会发生以下情况:有时,默认方向上存在的具有非常低值的箱子不会显示为水平方向 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='horizont

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

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()
在笔记本单元中执行以下代码(遗憾的是,我无法上传/应该生成两个直方图,在这两个直方图中,您最多可以看到分布的右/左箱子的差异。默认情况下,~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()
我还在这里链接了这些图:

-


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

我对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()

你的matplotlib版本是什么?我无法重现你的问题。3,-3处的步骤是matplotlib2.2。这里的图像看起来像是被裁剪过的。你能让代码和图像保持一致吗?这个代码生成的图像是什么?(它们应该有轴、标签等。)