Violin plot has tails that go beyond real data

조회 수: 42 (최근 30일)
shir shalom
shir shalom 2018년 12월 10일
답변: Adam Danz 2024년 10월 9일
Hi everyone,
I'm using the awesome "distributionPlot.m" from file exchange in order to plot some nice violins.
I've noticed that the violins have tails that don't reflect my data - it is under the lowest value and above the highest.
for example: here's violin of data that is ALL POSITIVE! how come it goes below zero?
appreciate any help,
shir
violin.png
  댓글 수: 2
Philip G
Philip G 2018년 12월 10일
What input arguments do you use for the distributionPlot function?
The plot has some histogram smoothing options as specified:
% histOpt : histogram type to plot
% 0 : use hist command (no smoothing, fixed number of
% bins)
% 1 : smoothened histogram using ksdensity with
% Normal kernel. Default.
% 1.1: smoothened histogram using ksdensity where the
% kernel is robustly estimated via histogram.m.
% Normal kernel.
% 2 : histogram command (no smoothing, automatic
% determination of thickness (y-direction) of bins)
Any smoothed histogram might give you tails outside of where you data lies. Use Option "0" for a "true" histogram.
shir shalom
shir shalom 2018년 12월 10일
thank you so much!
i used it and indeed it doesn't create the tails, but it also not a nice violin (attached).
can i smooth it somehow?uglyViolin.png

댓글을 달려면 로그인하십시오.

답변 (2개)

Ruggero G. Bettinardi
Ruggero G. Bettinardi 2018년 12월 11일
Hi Shir,
I uploaded an updated version of 'distributionPlot' on my FileXchange page, 'distributionPlot_OnlyPositive'. This version of the function works exactly as the original one, but avoid violins whose lower tail go below zero.
NOTE that, however, as this function is still based on normal kernel smoothing, it does not guarantee to plot violins whose lower/upper tail extend only in the exact range of your input values. It does only guarantee not to plot violins with tails extending below zero.
HTH
Ruggero
  댓글 수: 1
shir shalom
shir shalom 2018년 12월 11일
OMG Ruggero that is amazing!
Thank you so much for taking the time to solve this issue on (the great) distributionPlot.m.
I will try it ASAP and let you know how it went.
Thanks for your help,
Shir

댓글을 달려면 로그인하십시오.


Adam Danz
Adam Danz 2024년 10월 9일
The important concept to understand is that violin plots show a visual estimate of the data’s distribution beyond the observed values using a kernal density estimate based on the input data. It's up to the reader to interpret those results in context of the data.
Unlike boxchart, histogram, swarmchart, and other similar distribution visualizations, the violinplot makes inferences about the population rather than merely depicting the input data.
violinplot was introduced in MATLAB R2024b. A good example to understand the visualization is basing the violinplot on a single data point at y=0. The shape forms a gaussian curve centered at 0 with a standard deviation of 1. Compare the violin plot with the gaussian curve.
tiledlayout(2,1)
violinplot(nexttile(), 0, orientation='horizontal')
grid on
x = -3:.02:3;
y = gaussmf(x,[1,0]);
plot(nexttile, x, y)
ylim([-2 2])
grid on

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by