【问题标题】:Font size of axis labels in seabornseaborn中轴标签的字体大小
【发布时间】:2017-09-25 23:30:44
【问题描述】:

在 seaborn 中,如何仅更改 x 和 y 轴标签字体大小?除了使用“设置上下文”方法,有没有办法专门更改轴标签?这是我的代码:

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")

【问题讨论】:

  • 使用plt.xlabel('text', fontsize=size)ax.set_xlabel('text', fontdict={'fontsize' : size})
  • 谢谢,这行得通,但由于某种原因,它不会改变最后一对绘图在 x 和 y 方向上的字体。
  • 有多个子图?您需要为要应用的每个轴调用上述方法,并记住 Matplotlib 子图编号从 1 开始计数(与 Python 中的所有其他内容不同......)。

标签: python matplotlib seaborn


【解决方案1】:

更改绘图中所有 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)

【讨论】:

    猜你喜欢
    • 2021-03-11
    • 2016-11-11
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多