DeepSpace
DeepSpace

Reputation: 153

Use decades on the x-axis

I have a graph like so:

enter image description hereI 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

Answers (2)

Jody Klymak
Jody Klymak

Reputation: 5912

https://matplotlib.org/api/dates_api.html#matplotlib.dates.YearLocator

ax.xaxis.set_major_locator(matplotlib.dates.YearLocator(10))

Upvotes: 1

Alec
Alec

Reputation: 9575

You can explicitly set the x-ticks:

plt.xticks(np.arange(min(x), max(x)+1, 10.0))

Upvotes: 0

Related Questions