Back to demo index

gnuplot demo script: violin.dem

autogenerated by webify.pl on Tue Sep 15 23:10:41 2015
gnuplot version gnuplot 5.1 patchlevel 0
#
# Various ways of displaying distribution of y values in a data file
#

# Generate a reusable set of N random data points.
nsamp = 3000 
set print $viol1
do for [i=1:nsamp] {
    y = (i%4 == 0) ? 300. +  70.*invnorm(rand(0)) \
      : (i%4 == 1) ? 400. +  10.*invnorm(rand(0)) \
      :              120. +  40.*invnorm(rand(0))
    print sprintf(" 35.0 %8.5g", y)
}
unset print

set print $viol2
do for [i=1:nsamp] {
    y = (i%4 == 0) ? 300. +  70.*invnorm(rand(0)) \
      : (i%4 == 1) ? 250. +  10.*invnorm(rand(0)) \
      :               70. +  20.*invnorm(rand(0))
    print sprintf(" 34.0 %8.5g", y)
}
unset print
#

set border 2
set xrange [33:36]
set xtics ("A" 34, "B" 35)
set xtics nomirror scale 0
set ytics nomirror rangelimited
unset key

set jitter overlap first 2
set title "swarm jitter with a large number of small points approximates a violin plot"
set style data points

set linetype  9 lc "#80bbaa44" ps 0.5 pt 5
set linetype 10 lc "#8033bbbb" ps 0.5 pt 5

plot $viol1 lt 9, $viol2 lt 10


Click here for minimal script to generate this plot




set title "Gaussian random jitter"
unset jitter

J = 0.1
plot $viol1 using ($1 + J*invnorm(rand(0))):2 lt 9, \
     $viol2 using ($1 + J*invnorm(rand(0))):2 lt 10 


Click here for minimal script to generate this plot




set title "uniform random jitter"
J = 0.5
plot $viol1 using ($1 - 0.25 + J*rand(0)):2 lt 9, \
     $viol2 using ($1 - 0.25 + J*rand(0)):2 lt 10


Click here for minimal script to generate this plot




set title "Same data - kernel density"
set style data filledcurves below
set auto x
set xtics 0,50,500
unset ytics
set border 3
set key

plot $viol1 using 2:(1) smooth kdensity with filledcurves above y lt 9 title 'B', \
     $viol2 using 2:(1) smooth kdensity with filledcurves above y lt 10 title 'A'


Click here for minimal script to generate this plot