在Seaborn的联合图中增加文本大小

4
我正在使用Seaborn的jointplot生成一些散点图。
以下是我所做的示例及其结果:
from scipy import stats

x = np.arange(100) + np.random.randn(100)*20
y = np.arange(100) + np.random.randn(100)*20

g = sb.JointGrid(x, y, ratio=100)
g.plot_joint(sb.regplot)
g.annotate(stats.spearmanr)
g.ax_marg_x.set_axis_off()
g.ax_marg_y.set_axis_off()
plt.xlabel('X', fontsize=18)
plt.ylabel('Y', fontsize=18)
plt.tick_params(axis="both", labelsize=18)
plt.legend(fontsize=20)

这是生成的图表。
我该如何改变图表中显示的文本大小(相关系数和p值)? enter image description here

1
在导入之后添加 matplotlib.rc("legend", fontsize=20) 看起来可以正常工作。 - cel
@cel 这会影响我生成的其他图表吗? - siva82kb
2
是的,可以这样做。但是你可以使用上下文管理器(matplotlib.rc_context)仅为一个绘图设置它。 - mwaskom
请注意,据我所知,使用rc_context会覆盖seaborn的默认绘图样式,您必须显式调用set_style - cel
你为什么这么说?rc_context 的设计只设置你定义的特定参数,否则会从全局上下文继承参数。 - mwaskom
1个回答

3
这个例子来自Seaborn页面,很好地解释了它。
g = sns.JointGrid(x="total_bill", y="tip", data=tips)
g = g.plot_joint(plt.scatter,
             color="g", s=40, edgecolor="white")
g = g.plot_marginals(sns.distplot, kde=False, color="g")
rsquare = lambda a, b: stats.pearsonr(a, b)[0] ** 2
g = g.annotate(rsquare, template="{stat}: {val:.2f}",
           stat="$R^2$", loc="upper left", fontsize=12)

因此,您可以尝试这个。
g = sns.jointplot(x="", y="", data=df,kind='reg');
g = g.annotate(stats.pearsonr, fontsize=18)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接