Python和Matplotlib中的垂直直方图 [英] Vertical Histogram in Python and Matplotlib

查看:142
本文介绍了Python和Matplotlib中的垂直直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I make a vertical histogram. Is there any option for that or should it be built from the scratch? What I want is the upper graph to look like the below one but on vertical axis!

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和Matplotlib中的垂直直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆