如何制作垂直直方图。是否有任何选择,还是应该从头开始构建?我想要的是上图看起来像下图,但在垂直轴上!
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()
最佳答案
在 ax.hist
中使用 orientation="horizontal"
:
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()
关于python - Python 和 Matplotlib 中的垂直直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22333568/