Skip to content

Instantly share code, notes, and snippets.

@BedirYilmaz
Last active March 13, 2019 05:57
Show Gist options
  • Save BedirYilmaz/7e8ac6d93758462484e4dab15cdedabb to your computer and use it in GitHub Desktop.
Save BedirYilmaz/7e8ac6d93758462484e4dab15cdedabb to your computer and use it in GitHub Desktop.
Change x tick labels in pyplot
# https://stackoverflow.com/a/11250884/776348
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# We need to draw the canvas, otherwise the labels won't be positioned and
# won't have values yet.
fig.canvas.draw()
labels = ['m','y','l','a','b','e','l','s']
for label in ax.xaxis.get_ticklabels():
# tick.label.set_fontsize(19)
# specify integer or one of preset strings, e.g.
label.set_fontsize('x-small') # tick label attributes
label.set_rotation('vertical')
ax.set_xticklabels(labels) # tick label content
plt.xticks(range(len(labels))) # tick positions to make sure you get them printed in right frequency
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment