1

On the x-axis, I would like to display numbers (with no rotation) with rotated names below each number. I have the following but would like to separately rotate the names 'one', 'two' and 'three'.

plt.xticks([1,2,3], ['1\n one', '2\n two', '3\n three'], rotation=45]
Kevin
  • 74,910
  • 12
  • 133
  • 166
Alef
  • 195
  • 1
  • 6

1 Answers1

3

You can place major and minor ticks at the same positions. Here is a minimum example:

import pylab as pl

pl.clf()
ax = pl.gca()
ax.set_xticks([1, 2, 3])
ax.set_xticks([1, 2, 3], minor=True)
ax.set_xticklabels(['one', 'two', 'three'], minor=True)
pl.setp(ax.xaxis.get_minorticklabels(), rotation=-45)

for t in ax.get_xticklabels(minor=True):
    t.set_y(-0.03)

enter image description here

(With some inspiration from this answer.)

Community
  • 1
  • 1
Falko
  • 17,076
  • 13
  • 60
  • 105