Home > Net >  Why does Seaborn lineplot "size" argument end up as legend artist?
Why does Seaborn lineplot "size" argument end up as legend artist?

Time:11-09

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.

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()

enter image description here

What is the reason for this behavior, and what can be done to prevent it?

CodePudding user response:

Use the linewidth parameter to set the width of the line. The size parameter does something else. Check out the examples in the enter image description here

CodePudding user response:

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:

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()

enter image description here

Not sure what it's doing as a number though. You use linewidth to set the line size though:

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()

enter image description here

  • Related