seaborn中轴标签的字体大小

Font size of axis labels in seaborn

在 seaborn 中,如何只改变 x 轴和 y 轴标签的字体大小?除了使用 "set context" 方法,有没有办法专门更改轴标签?这是我的代码:

def corrfunc(x, y, **kws):

    r = stats.pearsonr(x, y)[0] ** 2
    ax = plt.gca()
    ax.annotate("r$^2$ = {:.2f}".format(r),
                xy=(.1, .9), xycoords=ax.transAxes, fontsize=16)
    if r > 0.6:
        col = 'g'
    elif r < 0.6:
        col = 'r'
    sns.regplot(x, y, color=col)
    return r

IC_Plot = sns.PairGrid(df_IC, palette=["red"])
IC_Plot.map_offdiag(corrfunc)

IC_Plot.savefig("Save_Pair.png")

更改绘图中所有 x 和 y 标签的字体大小的最简单方法是在脚本开头使用 rcParams 属性 "axes.labelsize",例如

plt.rcParams["axes.labelsize"] = 15

您还可以设置每个单独标签的字体大小

for ax in plt.gcf().axes:
    l = ax.get_xlabel()
    ax.set_xlabel(l, fontsize=15)