I want to plot a confusion matrix using Pylab. The class labels along the horizontal axis are long, so I want to plot them rotated vertically. However, I also want to plot them on top of the axis, not below.
This command can plot vertical labels on bottom:
pylab.imshow(confusion_matrix)
pylab.xticks(..., rotation='vertical')
and this command can plot horizontal labels on top without rotation:
pylab.matshow(confusion_matrix)
but I cannot find anything that does both. The following command does not work.
pylab.matshow(confusion_matrix)
pylab.xticks(..., rotation='vertical')
Can you suggest a way to plot a confusion matrix with xticks on top of the axis with vertical rotation? Thank you.
EDIT
Thank you, Mark, for your help. It got me on the right track by inspecting the tick properties more closely. The only difference with your answer and my desired answer is applying that idea to an AxesImage, not a plot. After investigation, here is the answer:
im = pylab.matshow(confusion_matrix)
for label in im.axes.xaxis.get_ticklabels():
label.set_rotation(90)
im.figure.show()
To those reading... don't forget about show()! I forgot that I needed to refresh the figure. See output below.