Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Plot, how to control the bar width and the gaps

Hope this is an easy question -- how to control the bar width and the gaps when plotting with Pandas?

Full code is here, reposted below:

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()

enter image description here

The result bar width is too thin and the gaps is too wide, how can I fix it? Thanks.

like image 952
xpt Avatar asked Dec 11 '15 22:12

xpt


1 Answers

You can set the width of the bars:

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

The result looks like this:

enter image description here

Make them thinner again:

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

enter image description here

like image 149
Mike Müller Avatar answered Sep 19 '22 07:09

Mike Müller