How to stop violin plot cutting off outliers or extreme values
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island
--
Chapters
00:00 How To Stop Violin Plot Cutting Off Outliers Or Extreme Values
00:47 Accepted Answer Score 7
01:39 Thank you
--
Full question
https://stackoverflow.com/questions/4553...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #matplotlib #graph #seaborn #graphvisualization
#avk47
ACCEPTED ANSWER
Score 7
The range over which the KDE is plotted for a matplotlib violinplot is the range of input values. This is defined pretty deep in the code, so there is no easy option to change that.
In contrast, the seaborn violinplot allows to have some good control over the KDE range. By default, it expands the shown KDE curve by twice the bandwidth of the KDE on each side of the plot. This is steered by the cut argument to sns.violinplot(, cut=2), which defaults to 2. If you set cut=0, you will obtain the same as the matplotlib violinplot. Together with the option to manually chose the KDE bandwidth as float, sns.violinplot(..., bw = 0.2, cut=2), you have a very good control over how the violinplot is displayed.
In conclusion, just use the seaborn violinplot if you need fine grained control over the range of the KDE curve.