Change xticklabels fontsize of seaborn heatmap

Question:

Here is my question:
I plot 7 variable’s coefficient using sns.clustermap()

  • x/y tickslabel seems really small(In my case, s1,s2,… s9)

My attempt

  • label='big ==> no effect
  • plt.tick_params(axis=’both’, which=’minor’, labelsize=12) ===> cbar label has changed, but the x/y axes looks the same.

Add

My code:

 ds =  pd.read_csv("xxxx.csv")
 corr = ds.corr().mul(100).astype(int)
 
 cmap = sns.diverging_palette(h_neg=210, h_pos=350, s=90, l=30, as_cmap=True)

 sns.clustermap(data=corr_s, annot=True, fmt='d',cmap = "Blues",annot_kws={"size": 16},)
Asked By: Han Zhengzu

||

Answers:

Consider calling sns.set(font_scale=1.4) before plotting your data. This will scale all fonts in your legend and on the axes.

My plot went from this,
enter image description here

To this,

enter image description here

Of course, adjust the scaling to whatever you feel is a good setting.

Code:

sns.set(font_scale=1.4)
cmap = sns.diverging_palette(h_neg=210, h_pos=350, s=90, l=30, as_cmap=True)
sns.clustermap(data=corr, annot=True, fmt='d', cmap="Blues", annot_kws={"size": 16})
Answered By: Nelewout

Or just use the set_xticklabels:

g = sns.clustermap(data=corr_s, annot=True, fmt='d',cmap = "Blues")
g.ax_heatmap.set_xticklabels(g.ax_heatmap.get_xmajorticklabels(), fontsize = 16)

To get different colors for the ticklabels:

import matplotlib.cm as cm
colors = cm.rainbow(np.linspace(0, 1, corr_s.shape[0]))
for i, ticklabel in enumerate(g.ax_heatmap.xaxis.get_majorticklabels()):
    ticklabel.set_color(colors[i])
Answered By: 5norre
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.