Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to replace the default x-tick labels with my year sequence, using this code:

plt.plot(np.median(trans_es, axis=0))
ax = plt.gca()
ax.set_xticklabels(list(range(2003, 2019)))
plt.show()

However, Matplotlib returns this figure to me:

It doesn't start with 2003, neither does it end in 2018. How can I correct this problem?

EDIT: This problem remains even I change the np.median(trans_es, axis=0) part to range(16)

plt.plot(x,y) should take both x and y as input. Then you would already get the correct scale out. Then you need to use ax.set_xticks to set the tick positions. Only then you may use ax.set_xticklabels to customize the labels. – ImportanceOfBeingErnest Mar 27, 2020 at 12:22

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.