简体   繁体   English

在散点图中突出显示异常值 plot

[英]Highlighting Outliers in scatter plot

I am using dataset "tips".我正在使用数据集“提示”。

Plotting scatter plot with below code使用以下代码绘制散点图 plot

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?我想显示异常值,假设在这种情况下,y 轴上 40 以上的点,颜色不同或大,或者是否可以在 40 处绘制水平?

Using seaborn.scatterplot you can leverage the "hue" parameter to plot groups in different color.使用 seaborn.scatterplot 您可以将“hue”参数用于不同颜色的 plot 组。 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')

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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