Changing the rotation of tick labels in Seaborn heatmap Changing the rotation of tick labels in Seaborn heatmap python python

Changing the rotation of tick labels in Seaborn heatmap


seaborn uses matplotlib internally, as such you can use matplotlib functions to modify your plots. I've modified the code below to use the plt.yticks function to set rotation=0 which fixes the issue.

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsdata = pd.DataFrame(np.random.normal(size=40*40).reshape(40,40))yticks = data.indexkeptticks = yticks[::int(len(yticks)/10)]yticks = ['' for y in yticks]yticks[::int(len(yticks)/10)] = keptticksxticks = data.columnskeptticks = xticks[::int(len(xticks)/10)]xticks = ['' for y in xticks]xticks[::int(len(xticks)/10)] = kepttickssns.heatmap(data,linewidth=0,yticklabels=yticks,xticklabels=xticks)# This sets the yticks "upright" with 0, as opposed to sideways with 90.plt.yticks(rotation=0) plt.show()

Plot


You can also call the methods of heatmap object:

    g = sns.heatmap(data,linewidth=0,yticklabels=yticks,xticklabels=xticks)    g.set_yticklabels(g.get_yticklabels(), rotation = 0, fontsize = 8)

I am not sure why this isn't in the documentation for sns.heatmap, but the same methods are described here: http://seaborn.pydata.org/generated/seaborn.FacetGrid.html

I believe these methods are available to every seaborn plot object but couldn't find a general API for that.