代码之家  ›  专栏  ›  技术社区  ›  Matt Pitkin

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

  •  3
  • Matt Pitkin  · 技术社区  · 8 年前

    能否在matplotlib中绘制直方图,使其看起来倒置,即直方图的底部沿顶轴,并“悬挂”下来?或者,如果使用 orientation='horizontal' ,这样直方图的底部就位于右手轴上?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Scott Boston    8 年前

    是,使用 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