[Matplotlib-users] width of bar plot when using pandas DatetimeIndex

Pierre Haessig pierre.haessig at crans.org
Sat Apr 8 03:49:13 EDT 2017


Hi,

I wonder if there is a documented behavior when making a barplot with 
datetimes (more precisely pandas DatetimeIndex) as the x values.

I've pasted an example below with matplotlib 2.0 and pandas 0.19.2.

In this experiment, it seems that the width of the bars is interpreted 
as a number of days, so if I want to plot monthly data without blanks, I 
have to put width = 31. So my question is: /is it a reliable behavior 
that the bar width is a number of days when working with a DatetimeIndex? /

Notice that it is not coherent with pandas behavior: when addiding +1 on 
a monthly datetime index it adds on month.

Also, with the default width value (0.8), some of the bars are not 
visible and I don't understand why, but maybe it's a separate issue.

best,

Pierre

The example:

a = pd.date_range('2015', '2016',freq='M')

ts = pd.Series([3.,2]*6, a)

plt.bar(a, ts);

plt.bar(a, ts, width=31);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170408/7e934731/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eadgedkoimhkmfdf.png
Type: image/png
Size: 4114 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170408/7e934731/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dgomnnplmonlhagf.png
Type: image/png
Size: 4114 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170408/7e934731/attachment-0001.png>


More information about the Matplotlib-users mailing list