In Pandas, I have a DataFrame of observations (baby bottle feeding volumes) that are indexed by a datetime and grouped by date:
...
bottles = bottles.set_index('datetime')
bottles = bottles.groupby(bottles.index.date)
I want to use matplotlib to plot the cumulative values as they increase each day--that is, show the volume of feedings as it increases each day and resets at midnight:
ax = plt.gca()
ax.xaxis.set_major_locator(mdates.DayLocator())
ax.xaxis.set_minor_locator(mdates.HourLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
bottles['volume'].cumsum().plot(kind='bar', figsize=[16,8])
ax.xaxis.grid(True, which="major")
ax.xaxis.grid(False, which="minor")
ax.yaxis.grid(True)
plt.gcf().autofmt_xdate()
plt.show()
I'd like to only label dates on the x-axis once per day, and I'd also like to only draw a vertical grid line on date boundaries (every 24 hours). Any recommendations for how to fix the above code?