简体   繁体   中英

Highlighting Outliers in scatter plot

I am using dataset "tips".

Plotting scatter plot with below code

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

在此处输入图像描述

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?

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

df['is_outlier'] = (df['total_bill'] >= 40)
sns.scatterplot(data=df, y='total_bill', hue='is_outlier')

With below code desired result achieved.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM