I\'m seeing some strange behavior in the x-axis auto-labeling for dates in matplotlib. When I issue the command:
from datetime import datetime as dt
plot( [ dt(2
It does feel like a bug; I would take it to the matplotlib mailing list and see what people there can say about it.
One workaround I can provide is the following:
from datetime import datetime as dt
from matplotlib import pylab as pl
fig = pl.figure()
axes = fig.add_subplot(111)
axes.plot( [ dt(2013, 1, 1), dt(2013, 5, 18)], [ 1 , 1 ], linestyle='None', marker='.')
ticks = axes.get_xticks()
n = len(ticks)//6
axes.set_xticks(ticks[::n])
fig.savefig('dateticks.png')
Apologies for the OO approach (which isn't what you did), but that makes it a lot easier to tie the ticks to the plot.
The number 6
is just the number of labels I want along the x-axis, and then I reduce the actual number of ticks that matplotlib came up with, by the calculated n
.