Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn scatterplot addition legend items

I'm seeing '1 and 2' as additional labels in my legend for a seaborn scatterplot. They'll disappear when I set the legend to False, but so does the legend I do want in there. Any idea where this comes from and how to prevent it from appearing?

This sample code generates the image with the issue;

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

df = pd.DataFrame({'restHR': np.random.randint(40,65, size=(100,)),
                   'Time': np.random.randint(0,10, size=(100,))})

sns.set()
fig, ax = plt.subplots()

ax = sns.scatterplot(df['Time'], df['restHR'], size=2, alpha=0.3, label="Race",linewidths=0)

plt.legend(frameon=False, bbox_to_anchor=(1,0.5), loc="center left",prop={'size': 8})
plt.subplots_adjust(right=0.75)

plt.show() 

enter image description here

like image 395
Chrisvdberge Avatar asked Jul 16 '26 05:07

Chrisvdberge


1 Answers

It's from size=2. The size parameter is used when you want varied size for the points given a grouped variable.

I am not sure why you have it there, but if you want to adjust the size of the symbol, use s=2 instead.

like image 196
Xiaoyu Lu Avatar answered Jul 18 '26 20:07

Xiaoyu Lu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!