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
–
.set_xticks()
on the axes will set the locations and
set_xticklabels()
will set the displayed text.
def test(axes):
axes.bar(x,y)
axes.set_xticks(x)
axes.set_xticklabels([i+100 for i in x])
–
Another function that might be useful, if you don't want labels for every (or even any) tick is axes.tick_params.
def test(axes):
axes.tick_params(axis='x',which='minor',direction='out',bottom=True,length=5)
New in matplotlib 3.5.0
ax.set_xticks now accepts a labels param to set ticks and labels simultaneously:
fig, ax = plt.subplots()
ax.bar(x, y)
ax.set_xticks(x, labels=[i + 100 for i in x])
# ^^^^^^
Since changing labels usually requires changing ticks, the labels param has been added to all relevant tick functions for convenience:
ax.xaxis.set_ticks(..., labels=...)
ax.yaxis.set_ticks(..., labels=...)
ax.set_xticks(..., labels=...)
ax.set_yticks(..., labels=...)
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.