如何在 matplotlib 中绘制颠倒的直方图?

Mat*_*kin 6 matplotlib histogram

您能否在 matplotlib 中绘制直方图,使其上下颠倒,即直方图的底部沿顶轴并且“悬挂”向下?或者,如果使用 绘图orientation='horizontal',则直方图的底部位于右侧轴上?

Sco*_*ton 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()
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述