Jitter points in gnuplot. Data input file format

Viewed 170

I am able to successfully reproduce Jitter examples from here: http://gnuplot.sourceforge.net/demo/violinplot.html

However, when I try to use my own data, the points are not "jittered".

Here is the data file (data.dat):

10 1 1 3 8 8 8
20 2 2 3 8 8 8
30 3 3 3 8 8 8

Here is a minimal gnuplot input file:

set jitter
plot 'data.dat' using 1:2 with points, '' u 1:3 with points, '' u 1:4 with points, '' u 1:5 with points, '' u 1:6 with points, '' u 1:7 with points

The points are right on top of each other, whereas I want points that are in the same place to be slightly offset (x-axis).

I've installed the latest version of gnuplot: $ gnuplot --version gnuplot 5.2 patchlevel 6

EDIT WITH SOLUTION: @Ethan's comment cleared it up for me. I'm able to get the jittering by reorganizing my input data file so that it's a single dataset, which contains internal "collisions", rather than reading in lots of individual data sets. e.g:

10 1
10 1
10 3
10 3
20 2
20 2
30 8
30 8

And my gnuplot file is now just:

set jitter
plot 'data.dat' using 1:2 with points
1 Answers

"set jitter" will not work across multiple data sets as noted in the comment. You could do something similar by adding a random displacement in the 'using' specifier.

plot for [col=2:7] 'data.dat' using 1:(column(col) + (rand(0)-0.5)/2.) with points

This is different from "set jitter" because all points will be randomly displaced, whereas with jitter only overlapping points are shifted and the displacement is not random.

enter image description here

Alternatively, since in your case the columns are distinct perhaps you want to shift systematically based on the column number:

plot for [col=2:7] 'data.dat' using (column(1)+col/4.) : (column(col))

enter image description here

Related