You can also format ticks and labels of the x axis pandas DateTimeIndex "manually" using the attributes of the pandas Timestamp object.
I found this to be much simpler than using locators from matplotlib.dates , which work with other datetime formats than pandas (if I'm not mistaken), and therefore sometimes show odd behavior if dates are not converted accordingly.
Here is a general example that shows the first day of each month as a label based on the attributes of pandas Timestamp objects:
import numpy as np import pandas as pd import matplotlib.pyplot as plt # data dim = 8760 idx = pd.date_range('1/1/2000 00:00:00', freq='h', periods=dim) df = pd.DataFrame(np.random.randn(dim, 2), index=idx) # select tick positions based on timestamp attribute logic. see: # https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Timestamp.html positions = [p for p in df.index if p.hour == 0 and p.is_month_start and p.month in range(1, 13, 1)] # for date formatting, see: # https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior labels = [l.strftime('%m-%d') for l in positions] # plot with adjusted labels ax = df.plot(kind='line', grid=True) ax.set_xlabel('Time (h)') ax.set_ylabel('Foo (Bar)') ax.set_xticks(positions) ax.set_xticklabels(labels) plt.show()
gives:

Hope this helps!
Cord kaldemeyer
source share