fig = plt.figure()
ax = fig.gca()
ts.plot(ax=ax)
I know I can set xlim inside pandas plotting routine: ts.plot(xlim = …), but how to change it after pandas plotting is done?
ax.set_xlim(( t0.toordinal(), t1.toordinal() )
works sometimes, but if pandas is formatting the xaxis as months from epoch, not days, this will fail hard.
Is there anyway to know how pandas has converted the dates to xaxis and then convert my xlim in the same way?
Thanks.
Best Answer
It works for me (with pandas 0.16.2) if I set the x-axis limits using
pd.Timestamp
values.Example:
Result:
Note that if you plot multiple time series in the same figure then make sure to set xlim/ylim after the last
ts.plot()
command, otherwise pandas will automatically reset the limits to match the contents.