首页 > 解决方案 > Seaborn:如何增加轴上标签的字体大小?

问题描述

这是我绘制热图的方法:

sns.heatmap(table, annot=True, fmt='g', annot_kws={'size':24})

问题是,size只设置热图中数字的字体大小。我应该使用哪个参数annot_kws来设置轴上标签的字体大小?

谢谢

标签: python-3.xmatplotlibseaborn

解决方案


您不能直接在调用中更改它们heatmap,但您可以指示 matplotlib 直接更改字体大小plt.rcParams使用上下文管理器

uniform_data = np.random.rand(10, 12)
plt.figure()
with plt.style.context({'axes.labelsize':24,
                        'xtick.labelsize':8,
                        'ytick.labelsize':16}):
    ax = sns.heatmap(uniform_data, annot=True, fmt='.1f', annot_kws={'size':6})
    ax.set_xlabel('x label')

在此处输入图像描述


推荐阅读