There are two elements in your question:
- How to control # ticks / tags on the chart
- How to change a 24-hour time to a 12-hour period
The axes of the set_xticks , set_yticks , set_xticklabels and set_yticklabels control set_yticklabels and labels:
import matplotlib.pyplot as plt plt.plot(range(10), range(10)) plt.gca().set_xticks(range(0,10,2)) plt.gca().set_xticklabels(['a{}'.format(ii) for ii in range(0,10,2)])
To change the time format, use pd.datetime.strftime: How can I convert 24-hour time to 12 hours?
import pandas as pd data = pd.Series(range(12), index=pd.date_range('2016-2-3 9:00','2016-2-3 20:00', freq='H')) ax = data.plot(xticks=data.index[::2]) ax.set_xticklabels(data.index[::2].map(lambda x: pd.datetime.strftime(x, '%I %p')))
This question covers an alternative approach to building with dates: Pandas timeline that sets major and minor ticks and labels along the x axis
source share