python pandas - editing axes tickmarks

56 views Asked by At

You can see the graph below which is from Jupyter. I'd like to edit the tick labels on x-axis which are currently a mess. This problem only occurs after I add the secondary axis. They represent years from 1922 to 2014. I'd like the graph to show only every 10th year. How can I do that?

enter image description here

1

There are 1 answers

4
Uvar On

You'll need the handle of your figure to access the axis. The following snippet will make you end up with a tick label every 10 years ..

import matplotlib.dates as mdates
fig, ax = plt.subplots()
 ... ... plot your things
ax.xaxis.set_major_locator(mdates.YearLocator(base=10))