I collect aggregated data in Python using Pandas and Matlplotlib. My axis setup commands do not work as a function from which of two similar functions I call to make line graphs. A working case is, for example:
import datetime import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates def format_x_date_month_day(ax): days = mdates.DayLocator() months = mdates.MonthLocator()
(see matplotlib.org , for example, a loop to create a line-by-line graph.) This gives us

Another approach, which should work and be much simpler, is to use df.plot.bar(ax=ax, stacked=True) , however it does not allow formatting the date axis with mdates :
plt.close('all') fig, ax = plt.subplots(1) df.plot.bar(ax=ax, stacked=True) format_x_date_month_day(ax) plt.show()

How can mdates and ax.figure.autofmt_xdate() be made to play well with df.plot.bar ?
python matplotlib pandas
eecharlie Dec 25 '17 at 1:10 2017-12-25 01:10
source share