1

See the violinplot: enter image description here

here I'm showing the points to show that the long tail of the violin is due to a single point. I would like to ignore these outliers points so that I have a more concise violin plot. Can I do that with seaborn when plotting the violin or do I have to remove them from the distribution myself?

martinako
  • 2,690
  • 1
  • 25
  • 44
  • 2
    You have to remove them manually before passing the data for plotting. If we look into seaborn's [violin plot api](https://seaborn.pydata.org/generated/seaborn.violinplot.html), there is no parameter specified for removing extreme outliers. – Kishore Sampath Aug 24 '21 at 14:30
  • 1
    you can also change the y-axis upper limit to clip the tail without changing the data: `ax = sns.violinplot(…) ; ax.set_ylim(ymax=2)` – mozway Aug 24 '21 at 14:34
  • @JohanC I would personally clean up the data, just provided an alternative ;) – mozway Aug 24 '21 at 18:21
  • You'll need to manage the data in the dataframe and then plot. – Trenton McKinney Aug 24 '21 at 23:12

1 Answers1

2

You can do it by excluding the outlier data while passing it through the plot function. e.g.

sns.violinplot(y = df[df["Column"]<x]["Column"]) 

wherein, df is your dataframe. Column is the name of the column you want to plot and x is the outlier value that you want to exclude.

hbstha123
  • 1,260
  • 11
  • 23