How to add legend to seaborn.scatterplot?
You can do so by adding a hue
argument.
fig, ax = plt.subplots(1, 2, figsize=(16, 5))
bar = sns.barplot(
x=df.loc[:, 'Sex'],
y=df.loc[:, 'Salary'],
ax=ax[0]
)
bar.set(ylim=(10000, 30000))
sca = sns.scatterplot(
data=df,
x=df.loc[:, 'yearsinrank'],
y=df.loc[:, 'Salary'],
hue=df.loc[:, 'Sex'], # hue argument to specify grouping variable
ax=ax[1]
)
sca.set(ylim=(10000, 40000), xlim=(-5, 30))
plt.show()