Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit the width of bars using dataframe.plot() function in matplotlib

I am making a stacked bar plot using:

DataFrame.plot(kind='bar',stacked=True) 

I want to control width of bars so that the bars are connected to each other like a histogram.

I've looked through the documentation but to no avail - any suggestions? Is it possible to do it this way?

like image 893
Osmond Bishop Avatar asked Feb 12 '13 02:02

Osmond Bishop


People also ask

How do I increase space between bars in Matplotlib?

The space between bars can be added by using rwidth parameter inside the “plt. hist()” function. This value specifies the width of the bar with respect to its default width and the value of rwidth cannot be greater than 1.


1 Answers

For anyone coming across this question:

Since pandas 0.14, plotting with bars has a 'width' command: https://github.com/pydata/pandas/pull/6644

The example above can now be solved simply by using

df.plot(kind='bar', stacked=True, width=1) 

See pandas.DataFrame.plot.bar or pandas.DataFrame.plot with kind='bar'.

When changing the width of the bars, it might also be appropriate to change the figure size by specifying the figsize= parameter.

like image 91
Murkbeard Avatar answered Sep 30 '22 06:09

Murkbeard