Anna
Anna

Reputation: 29

sns.scatter plot python, specify size

I have the sns.scatterplot below, where I have set the size to Gap. The Gap values that have come up are 0, 0.8, 0.16 and 0.24, however the values in my dataframe are 0, 0.5, 1 and 2. How can I set them to equal the values in my dataframe?

ax = sns.scatterplot(x='Number tapes', y='Ic', hue="Angle of twist (degree)", size="Gap", data=Ic_layers)

Upvotes: 0

Views: 1360

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40707

The values that are shown in the legend seem inconsistent with what you are saying the range of data is in your dataframe, but anyway...

You can use legend='full' in the call to scatterplot() to force seaborn to show a legend item for each of the levels of your hues/sizes variable.

N=50
df = pd.DataFrame({'x': np.random.random(size=(N,)), 'y': np.random.random(size=(N,)),
                   'size': np.random.choice([0, 0.5, 1, 2], size=(N,))})
fig, (ax1, ax2) = plt.subplots(1,2)
sns.scatterplot(x="x", y="y", size="size", data=df, ax=ax1)
ax1.set_title('legend="brief" (default)')
sns.scatterplot(x="x", y="y", size="size", data=df, legend='full', ax=ax2)
ax2.set_title('legend="full"')

enter image description here

Upvotes: 1

Related Questions