1
votes

Bit of a sticky situation here. Basically, I have about 6 files of x,y,z points (each has something like 200 points in) which are all related to one another. What I am looking to do is make a 3D (splot) of this data, which I can already do, only with lines between the corresponding lines - so line 34 in file 1 is on a line with line 34 in file 2 and so on.

I can tell I may not be explaining it the best here, so I will try and give some context. It is a simulation program which calculates the positions of particles and then applies different forces to them. After every second of simulation it outputs a file, and therefore it would be plotting the paths of these particles in 3D with lines.

In order to solve this I have already thought of giving each particle its own file, however as I have to load each file (splot 'file.csv' etc) each time this would be rather slow - and would increase file IO needed. Any help would be greatfully appreciated.

Thanks!

1

1 Answers

3
votes

This is actually relatively easy to do using the with vectors plotting style and the paste command. Imagine you have the following four files:

# File 1 named data1
0 0 0
1 1 1

and

# File 2 named data2
1 0 0
1 2 2

and

# File 3 named data3
1 1 0
1 3 2

and

# File 4 named data4
1 0 2
2 1 2

Particle 1 will follow the trajectory 0 0 0 -> 1 0 0 -> 1 1 0 -> 1 0 2 and particle 2 will follow the trajectory 1 1 1 -> 1 2 2 -> 1 3 2 -> 2 1 2.

The with vectors style joins two points, for which you need 6 data points in 3D, that need to be on the same file. This can be achieved using the paste command:

paste data1 data2 > data1-2

leads to file data1-2 looking like this:

# File 1 named data1    # File 2 named data2
0 0 0   1 0 0
1 1 1   1 2 2

but this is just to explain what's going on. This is better done within gnuplot, with i iterating over files and j iterating over particles (with j = 0 being the first particle):

nfiles = 4 # number of files
nparticles = 2 # number of particles

splot for [i=1:1] for [j=0:nparticles-1] "< paste data".i." data".(i+1) \
u 1:2:3:($4-$1):($5-$2):($6-$3) every ::j::j w vectors lc j+1 t "Particle ".(j+1), \
for [i=2:nfiles-1] for [j=0:nparticles-1] "< paste data".i." data".(i+1) \
u 1:2:3:($4-$1):($5-$2):($6-$3) every ::j::j w vectors lc j+1 not

Ta-dah!

enter image description here