Home > Back-end >  Highlighting Outliers in scatter plot
Highlighting Outliers in scatter plot

Time:01-31

I am using dataset "tips".

Plotting scatter plot with below code

sns.scatterplot(data=df['total_bill'])

enter image description here

I want to show the outliers let's say in this case points which are above 40 on y-axis, in different color or big or is it possible to draw a horizontal like at 40?

CodePudding user response:

With below code desired result achieved.

sns.scatterplot(data=df, y='total_bill', x=range(0,244), hue='is_outlier')

enter image description here

CodePudding user response:

Using seaborn.scatterplot you can leverage the "hue" parameter to plot groups in different color. For your example the following should work

is_outlier = (df['total_bill'] >= 40)
sns.scatterplot(data=df['total_bill'], hue=is_outlier)
  •  Tags:  
  • Related