[英]Why does Seaborn lineplot "size" argument end up as legend artist?
In a simple lineplot from Seaborn sample data, adding a "size" argument to control linewidth automatically adds an artist/handle to the legend generated from the "label" argument.在来自 Seaborn 样本数据的简单线图中,添加“大小”参数来控制线宽会自动向“标签”参数生成的图例添加艺术家/句柄。
import seaborn as sns
from matplotlib import pyplot as plt
df = sns.load_dataset('geyser')
fig, ax = plt.subplots()
sns.lineplot(
x=df.waiting,
y=df.duration,
label='Label',
size=3,
ax=ax
)
plt.show()
What is the reason for this behavior, and what can be done to prevent it?这种行为的原因是什么,可以采取什么措施来防止它?
Use the linewidth
parameter to set the width of the line.使用linewidth
参数设置线条的宽度。 The size parameter does something else. size 参数还有其他作用。 Check out the examples in the docs to see how to use it.查看文档中的示例以了解如何使用它。 The image below gives a good impression, and also makes it clear why the parameter results in a legend entry.下图给人留下了很好的印象,也清楚地说明了为什么参数会导致图例条目。
The size is used to group, and will have different size lines based on a category.尺寸用于分组,根据类别会有不同的尺寸线。
For example you can have different size based on the kind
column:例如,您可以根据kind
列有不同的大小:
import seaborn as sns
from matplotlib import pyplot as plt
df = sns.load_dataset('geyser')
fig, ax = plt.subplots()
sns.lineplot(
x=df.waiting,
y=df.duration,
label='Label',
size = df['kind'],
ax=ax
)
plt.show()
Not sure what it's doing as a number though.虽然不确定它作为一个数字在做什么。 You use linewidth
to set the line size though:您可以使用linewidth
来设置线条大小:
import seaborn as sns
from matplotlib import pyplot as plt
df = sns.load_dataset('geyser')
fig, ax = plt.subplots()
sns.lineplot(
x=df.waiting,
y=df.duration,
label='Label',
linewidth = 3,
ax=ax
)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.