图例大小/标记在Seaborn中 [英] Legend size/marker in relplot seaborn

查看:51
本文介绍了图例大小/标记在Seaborn中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找SO,以增加图例中的图例/色相大小.

plt.rcParams["axes.labelsize"] = 20g = sns.relplot(x ='Time(days)',y ='Duration Total(s)',hue ='Outcome',data = t1,height = 15,Aspect = 1,s = 50);plt.suptitle("a_10",fontsize = 25,fontweight ='bold') 

我似乎无法全神贯注.有太多混合参考,这一切都令人困惑.

解决方案

我花了一些时间对此进行深入研究,是的,您说得令人困惑是正确的.

我还将假设您是在谈论文本大小,而不是标记大小.

起作用的方式

我建议您使用两种主要方法来增加图例的大小(从中,还有一个答案可以解决直接修改图例的问题.它使用 FacetGrid 的私有属性 _legend 并直接增加文本大小:

  g = sns.relplot(x ='sepal_length',y ='sepal_width',hue ='species',data = iris)plt.setp(g._legend.get_texts(),fontsize = 16) 

但是,此方法严重破坏了格式.乍一看,我认为这是因为 FacetGrid 使用图例尺寸计算其大小.因此,事后更改图例会使事情搞砸.

该怎么办?

根据我的研究,似乎没有简单的方法可以执行所需的操作.您可以将问题提交到 seaborn仓库,也许他们会解决(您可以参考你的问题).更有希望的是,有一种 方法可以做到这一点,他们将简单地指出如何实现.

祝你好运:)

I've been looking in SO for increasing legend/hue size in relplot.

plt.rcParams["axes.labelsize"] = 20
g = sns.relplot(x='Time(days)', y='Duration Total (s)', hue='Outcome', data=t1,height=15, aspect=1, s=50);
plt.suptitle("a_10",fontsize=25, fontweight='bold')

I can't seem to wrap my heads around it. There're so many mixed references, it's all a bit confusing.

解决方案

I've spent some time digging through this, an yes, you're right to say it's confusing.

I will also assume you are talking about text size, and not marker size.

Ways that work

There are two main ways I would suggest you to increase the legend size (retrieved from here):

  • Scaling up the font globally using sns.set(). For example:

sns.set(font_scale=1.5)
# plotting code here...

  • Scaling up the font locally using sns.plotting_context(). For example:

with sns.plotting_context("notebook", font_scale=1.5):
    # plotting code here...

The problem with both approaches is that they also increase the size of other elements. So, for example, axis labels will grow alongside the legend:

Way that doesn't work

In the mentioned SO link, there's also an answer that addresses directly modifying the legend. It uses the private property _legend of the FacetGrid and increase the text size directly:

g = sns.relplot(x='sepal_length', y='sepal_width', hue='species', data=iris)
plt.setp(g._legend.get_texts(), fontsize=16)

This method, however, severely messes up with the formatting. From a quick glance, I think it happens because FacetGrid calculates its size using the legend dimensions. So, altering the legend afterwards messes things up.

What to do?

From my research, it looks like there's no simple way to do what you want. You can submit an issue to the seaborn repository and maybe they will fix it (you can give a reference to your question). More hopefully, there is a way to do it and they will simply point out how.

Good luck :)

这篇关于图例大小/标记在Seaborn中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆