Reputation: 153
I have a graph like so:
I use this code to format my x-axis
ax.xaxis.set_major_locator(matplotlib.dates.YearLocator())
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y'))
But now I have a lot of years and I want to use decades only on the x-axis: 1970 1980 1990 2000 and so on. How can I acheive this?
Upvotes: 1
Views: 348
Reputation: 5912
https://matplotlib.org/api/dates_api.html#matplotlib.dates.YearLocator
ax.xaxis.set_major_locator(matplotlib.dates.YearLocator(10))
Upvotes: 1
Reputation: 9575
You can explicitly set the x-ticks:
plt.xticks(np.arange(min(x), max(x)+1, 10.0))
Upvotes: 0