1

I'd like to change the xticks on my plot. Shown here is a time series for my parameter of interest, with

  • y14 = years 1930-1959
  • y24 = years 1960-1989
  • y34 = years 1990-2020.

Whereas B14, B24, and B34 are numbers ranging from 0-200. I want to change the xticks to only show the beginning and end of each time period. i.e 1930, 1960, 1990, & 2020.

plt.figure()
plt.subplot(2,1,1)
plt.plot(y14,B14, 'o')
plt.plot(y24,B24, 'o')
plt.plot(y34,B34, 'o')
plt.show()

plot

I've tried to change the number of bins by using

plt.locator_params(axis= 'x', tight=True, nbins=4)

However this did not get me where I want. I'm wondering if changing the spacing between bins to 30 years at the same time would do the trick? Or if anybody has any suggestions. Even showing the first xtick value (1930) has proven difficult for a beginner.

Thanks all.

Zephyr
  • 11,891
  • 53
  • 45
  • 80

1 Answers1

0

Maybe with plt.xticks you can achieve your goal?

plt.xticks([1930, 1960, 1990, 2020])

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80