Pandas Plot, how to control the bar width and the gaps
11,639
You can set the width
of the bars:
ax = df.set_index(['person']).plot(kind='barh', width=1.0)
The result looks like this:
Make them thinner again:
ax = df.set_index(['person']).plot(kind='barh', width=0.5)
Author by
xpt
#SOreadytohelp On 2020-10-31 On 2020-09-15: On 2020-04-15: On 2020-04-12: On 2020-04-02:
Updated on June 15, 2022Comments
-
xpt almost 2 years
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()
The result bar width is too thin and the gaps is too wide, how can I fix it? Thanks.
-
Bode over 5 yearsWhat about removing the space between the bars and still maintaining the width of the bar
-
Mike Müller over 5 yearsThan you wold have white space either at the top or the bottom. Does not add anything, I guess.