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


i'm plotting heatmap in seaborn. problem have many squares in plot x , y labels close each other useful. i'm creating list of xticks , yticks use. passing list function rotates labels in plot. nice have seaborn automatically drop of ticks, barring able have yticks upright.

import pandas pd import numpy np import seaborn sns  data = pd.dataframe(np.random.normal(size=40*40).reshape(40,40))  yticks = data.index keptticks = yticks[::int(len(yticks)/10)] yticks = ['' y in yticks] yticks[::int(len(yticks)/10)] = keptticks  xticks = data.columns keptticks = xticks[::int(len(xticks)/10)] xticks = ['' y in xticks] xticks[::int(len(xticks)/10)] = keptticks  sns.heatmap(data,linewidth=0,yticklabels=yticks,xticklabels=xticks) 

enter image description here

seaborn uses matplotlib internally, such can use matplotlib functions modify plots. i've modified code below use plt.yticks function set rotation=0 fixes issue.

import pandas pd import numpy np import matplotlib.pyplot plt import seaborn sns   data = pd.dataframe(np.random.normal(size=40*40).reshape(40,40))  yticks = data.index keptticks = yticks[::int(len(yticks)/10)] yticks = ['' y in yticks] yticks[::int(len(yticks)/10)] = keptticks  xticks = data.columns keptticks = xticks[::int(len(xticks)/10)] xticks = ['' y in xticks] xticks[::int(len(xticks)/10)] = keptticks  sns.heatmap(data,linewidth=0,yticklabels=yticks,xticklabels=xticks)  # sets yticks "upright" 0, opposed sideways 90. plt.yticks(rotation=0)   plt.show() 

plot


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -