4

I created a script to plot the columns of a dataset using violin plots to show the distribution of the data points starting from the Gnuplot Demo Scripts. However, I can't solve the following error:

"violinplot.gnu", line 27: all points y value undefined!

Does anyone have any idea?

The script:

reset

set terminal pdfcairo size 20,14 enhanced font 'Times,28'
set output 'violinplot.0.pdf'

set datafile separator ','

set table $kdensity1
plot 'profile.csv' using 2:(1) smooth kdensity bandwidth 10. with filledcurves above y lt 9 title 'B'
unset table
unset key

print $kdensity1

set border 2
#unset margins
#unset xtics
set ytics nomirror rangelimited
set title "Distribution of times in milliseconds"

set boxwidth 0.075
set style fill solid bo -1
set errorbars lt black lw 5

set xrange [-6:6]
plot $kdensity1 using (1 + $2/1.):1 with filledcurve x=1 lt 10, \
     $kdensity1 using (1 - $2/1.):1 with filledcurve x=1 lt 10

The dataset is in a CSV format as follows (and each column contains time in milliseconds):

1,1814,604,840,1306,13623
2,2195,68,908,1380,14416
3,1173,70,887,512,14301
4,1286,112,982,1541,9549
5,630,97,869,1321,5725
6,1227,689,917,393,4700
7,3402,357,951,500,5431
8,3429,120,969,1661,6281
...

Gnuplot Version 5.2 patchlevel 2

Nicola
  • 395
  • 2
  • 13

1 Answers1

0

The reason for your error is simple but "nasty" and hidden.

Your input data is comma separated. However, if you plot to a table via set table $kdensity the default column separator is whitespace. That's why gnuplot doesn't find any data in column 2.

I guess since gnuplot 5.2.2. you could set set table $kdensity separator comma. But in order to get a comma as separator you have to use the "plotting style" with table (e.g. plot FILE u 1:2 w table). However, with table and smooth ... do not work together. Either you use with table and you will get the comma but not "smoothed" or you "smooth" and you will not get the comma.

Two possible solutions:

  • after plotting to the smoothed table set your separator to whitespace (see example below).

or alternatively,

  • change your input data to whitespace separated.

If you want plot the original (comma separated) data as well, then you have two different column separators. Then you have to apply another workaround.

Script: (works with gnuplot>=5.2.2)

### violin plot with comma separated input data
reset session

# create some random test data (comma separated)
set table $Data separator comma
    set samples 100
    n = 0
    plot for [i=1:3] '+' u (n=n+1):(invnorm(rand(0))*i*25 +i*200) w table
unset table

set datafile separator ','

set table $kdensity
    set samples 1000
    plot $Data using 2:(1) smooth kdensity bandwidth 10.
unset table

set datafile separator whitespace
set key noautotitle
set style fill solid 0.7

plot $kdensity u (1 + $2/1.):1 w filledcurves x=1 lt 10, \
           ''  u (1 - $2/1.):1 w filledcurves x=1 lt 10
### end of script

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72