4
votes

I want to create a plot like this with gnuplot:

enter image description here

I have different data points for a fixed moment in time. I want to group these data points around the representing x value. These datapoints come from different data files which look like this:

9 0.333
9 0.308
9 0.289
15 0.356
15 0.836
15 0.364
15 0.347
0 0.386
0 0.318
0 0.347
0 0.322
12 0.351
12 0.314
12 0.314

Currently I plot the data using a loop like this:

set xtics (0, 3, 6, 9, 12, 15, 18, 21)
plot for [i=1:15] sprintf('file_%i.dat', i) using 1:2 with points

but they're overlapping. How can I do this using gnuplot?

1

1 Answers

2
votes

You would probably have to set an offset for each set of points manually, like this:

#!/usr/bin/env gnuplot

o1 = 0.1 # x-offset for each set of points on plot
n = 15   # number of files, integer
# x-offset for leftmost set of points.
# this will center all sets of points around the central x value,
# whether there are an even or odd number of sets
o2 = (n/2.0 - 0.5) * o1

set xtics (0, 3, 6, 9, 12, 15, 18, 21)

plot for [i=1:n] sprintf('file_%i.dat', i) using ($1-o2+i*o1):2 with points

(I think this should work, but I can't test it right now.)