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 My guess is because in your code set_xticks is getting a generator object, not a list. Try list([i+100 for i in x)] instead. rabs Feb 20, 2014 at 14:55

.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])
                plt.xticks(position, label) works while set_xticks on axis like subplots doesnt and one needs another call set_xticklabels. i call bad api on pyplot
– droid192
                Jan 31, 2019 at 9:35

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.