How to stop violin plot cutting off outliers or extreme values
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Island
--
Chapters
00:00 Question
01:02 Accepted answer (Score 6)
02:15 Thank you
--
Full question
https://stackoverflow.com/questions/4553...
Question links:
[image]: https://i.stack.imgur.com/4PuVK.png
--
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.