Python 更改seaborn热图的xticklabels字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34706845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change xticklabels fontsize of seaborn heatmap
提问by Han Zhengzu
Here is my question:
I plot 7 variable's coefficient using sns.clustermap()
figure here:
这是我的问题:
我
在这里使用 sns.clustermap()图绘制了 7 个变量的系数:
http://i4.tietuku.com/ab10ee8d1983361f.png
http://i4.tietuku.com/ab10ee8d1983361f.png
- x/y tickslabel seems really small(In my case, s1,s2,... s9)
- x/y tickslabel 似乎很小(在我的情况下,s1,s2,... s9)
My attempt
我的尝试
label='big
==> no effect- plt.tick_params(axis='both', which='minor', labelsize=12) ===> cbar lable has changed, but the x/y axes looks the same.
label='big
==> 没有效果- plt.tick_params(axis='both', which='minor', labelsize=12) ===> cbar 标签已更改,但 x/y 轴看起来相同。
http://i11.tietuku.com/5068224d5bbc7c00.png
http://i11.tietuku.com/5068224d5bbc7c00.png
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},)
采纳答案by N. Wouda
Consider calling sns.set(font_scale=1.4)
before plotting your data. This will scale all fonts in your legend and on the axes.
sns.set(font_scale=1.4)
在绘制数据之前考虑调用。这将缩放图例和轴上的所有字体。
To this,
对此,
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})
回答by 5norre
Or just use the set_xticklabels:
或者只使用 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)