【问题标题】:Pandas Plot, how to control the bar width and the gapsPandas Plot,如何控制条形宽度和间隙
【发布时间】:2016-03-17 22:41:18
【问题描述】:

希望这是一个简单的问题——使用 Pandas 绘图时如何控制条形宽度和间隙?

Full code is here,转发如下:

df = pd.DataFrame({
        'person':[x*3 for x in list('ABCDEF')],
        'score1':np.random.randn(6),
        'score2':np.random.randn(6),
        'score3':np.random.randn(6),
        'score4':np.random.randn(6),
        'score5':np.random.randn(6)
                   })
print(df)
ax = df.set_index(['person']).plot(kind='barh')
ax.invert_yaxis()

结果栏宽度太细,间隙太宽,我该如何解决?谢谢。

【问题讨论】:

    标签: python pandas plot bar-chart


    【解决方案1】:

    您可以设置条形的width

    ax = df.set_index(['person']).plot(kind='barh', width=1.0)
    

    结果如下:

    让它们再次变薄:

    ax = df.set_index(['person']).plot(kind='barh', width=0.5)
    

    【讨论】:

    • 如何去除条之间的空间并仍然保持条的宽度
    • 比你想在顶部或底部有空白。我猜没有添加任何东西。
    猜你喜欢
    • 1970-01-01
    • 2019-10-31
    • 2020-01-21
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多