python - Python 和 Matplotlib 中的垂直直方图

标签 python numpy matplotlib plot histogram

如何制作垂直直方图。是否有任何选择,还是应该从头开始构建?我想要的是上图看起来像下图,但在垂直轴上!

from matplotlib import pyplot as plt
import numpy as np
sample=np.random.normal(size=10000)
vert_hist=np.histogram(sample,bins=30)
ax1=plt.subplot(2,1,1)
ax1.plot(vert_hist[0],vert_hist[1][:-1],'*g')

ax2=plt.subplot(2,1,2)
ax2.hist(sample,bins=30)
plt.show()

enter image description here

最佳答案

ax.hist 中使用 orientation="horizo​​ntal":

from matplotlib import pyplot as plt
import numpy as np

sample = np.random.normal(size=10000)

vert_hist = np.histogram(sample, bins=30)
ax1 = plt.subplot(2, 1, 1)
ax1.plot(vert_hist[0], vert_hist[1][:-1], '*g')

ax2 = plt.subplot(2, 1, 2)
ax2.hist(sample, bins=30, orientation="horizontal");
plt.show()

enter image description here

关于python - Python 和 Matplotlib 中的垂直直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22333568/

相关文章:

python - 使用 pyspark 创建 spark 数据框时出现 Py4J 错误

python-2.7 - 使用 Python 查找多项式根——可能的 Numpy 扩展错误

python - django 查看 session ID - 未登录的用户缺少

python - 在 Python 中絮凝数据

python - 如何在seaborn中加载3D numpy数组作为数据帧

python - 如何在Python上增量创建稀疏矩阵?

django - 如何在 matplotlib 中向图形添加绘图?

python - 将注释框添加到 matplotlib 等高线/热图图

python - 将可旋转的 3D 绘图从 Python 导出到 HTML

python - Python如何从Cursor执行结果中获取值