width of bar plot when using pandas DatetimeIndex

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

width of bar plot when using pandas DatetimeIndex

Pierre Haessig


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.



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

Matplotlib-users mailing list
[hidden email]