Today I struggled a bit with pylab's plot_date function and overlapping date tick labels:

After some googling, I found that pylab offers nice flexible date tick control and formatting. I added a date tick locator and a date formatter to the mix as follows:
import pylab import matplotlib import matplotlib.dates fig = pylab.figure() ax = fig.gca() # Plotting stuff here ... ax.plot_date(dates, values, 'b.-') # Set major x ticks on Mondays. ax.xaxis.set_major_locator( matplotlib.dates.WeekdayLocator(byweekday=matplotlib.dates.MO) ) ax.xaxis.set_major_formatter( matplotlib.dates.DateFormatter('%a %d\n%b %Y') )
and now I have this plot:

Nice.
Thanks. I used this. It saved
Thanks. I used this. It saved me at least 15 minutes.
Thanks So much for share this
Thanks So much for share this information, i was needing this code to add my locator, because im not than skilful to realice by myself.
bruststraffung
Post new comment