user308827
user308827

Reputation: 22011

Explicitly labeling end points in matplotlib graph

In the matplotlib graph above, the x-axis ranges from 850 - 2015. I would like them to be explicitly labeled. Is there a way to force matplotlib to do that?

I am doing this: ax.set_xlim([min(xvar), max(xvar)]), here xvar is the x-axis array ranging from 850 - 2015

Upvotes: 1

Views: 1327

Answers (1)

Yunhe
Yunhe

Reputation: 665

try set_xticks and set_xticklabels to set the location and content of labels.

import matplotlib.pyplot as plt
a = plt.subplot(1,1,1)
a.plot([1,2,3,4,5,6,7,8,9,10])
a.set_xlim(1,10.5)
a.set_xticks([0, 5, 10, 10.5])
a.set_xticklabels([0, 5, 10, 10.5])

enter image description here

Upvotes: 1

Related Questions