簡體   English   中英

為什么 Seaborn 線圖“大小”爭論最終成為傳奇藝術家?

[英]Why does Seaborn lineplot "size" argument end up as legend artist?

在來自 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()

在此處輸入圖片說明

這種行為的原因是什么,可以采取什么措施來防止它?

使用linewidth參數設置線條的寬度。 size 參數還有其他作用。 查看文檔中的示例以了解如何使用它。 下圖給人留下了很好的印象,也清楚地說明了為什么參數會導致圖例條目。

在此處輸入圖片說明

尺寸用於分組,根據類別會有不同的尺寸線。

例如,您可以根據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()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM