如何在Matplotlib中绘制一个倒置的直方图?

6

您能在matplotlib中绘制一个直方图,使其上下颠倒吗?也就是说,直方图的底部位于顶部轴线上,并且是"悬挂"的状态?或者,如果使用orientation='horizontal'进行绘制,则直方图的底部位于右侧轴线上?

1个回答

5

是的,使用 invert_yaxis

df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
             'b':[1,1,1,3,2,2,2]})
ax = df.plot.hist()
ax.invert_yaxis()

输出:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接