为什么 Seaborn lineplot "size" 参数最终成为传奇艺术家?
Why does Seaborn lineplot "size" argument end up as legend artist?
在来自 Seaborn 示例数据的简单线图中,添加“大小”参数来控制线宽会自动向“标签”参数生成的图例添加 artist/handle。
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()
这种行为的原因是什么,可以采取什么措施来预防?
使用linewidth
参数设置线条的宽度。 size 参数还有其他作用。查看 docs 中的示例,了解如何使用它。下图给人的印象很好,也很清楚为什么参数会导致图例条目。
尺寸是用来分组的,会根据类别有不同的尺寸线。
例如,您可以根据 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()
虽然不确定它作为数字在做什么。您使用 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()
在来自 Seaborn 示例数据的简单线图中,添加“大小”参数来控制线宽会自动向“标签”参数生成的图例添加 artist/handle。
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()
这种行为的原因是什么,可以采取什么措施来预防?
使用linewidth
参数设置线条的宽度。 size 参数还有其他作用。查看 docs 中的示例,了解如何使用它。下图给人的印象很好,也很清楚为什么参数会导致图例条目。
尺寸是用来分组的,会根据类别有不同的尺寸线。
例如,您可以根据 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()
虽然不确定它作为数字在做什么。您使用 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()