'Plotting file rows as a function of first row in sequence with gnuplot

I am trying to animate the time evolution of the probability density of a wave-function of a system (1D), and already created a file with the amplitude of each point in x: the first row of the file is the x coordinate partition and the following rows are the amplitude of the those points every time-step.

This is a simplified example:

0.0 0.2 0.4 0.6 0.8 1.0 #x partition
2.0 2.1 2.3 2.2 1.9 1.6 #1st time-step amplitud value of each 
1.9 2.0 2.2 2.2 2.1 1.9 #2nd time-step amplitud value of each
          .
          .
          .
4.0 4.2 3.9 3.5 3.2 2.9 #nth time-step amplitud value of each

The point is that every time-step (i) I have to plot the i-th row versus the first row, and don't know how to do it.

Ultimately I would like to make an animated gif with gnuplot using this data file.



Solution 1:[1]

Your data is in matrix format, you should use the keyword matrix.

The problem is that gnuplot wants either the x and y coordinates as first row and first column (matrix nonuniform), or neither.

To circumvent this you need to add the time as a y coordinate in first row, which is not too difficult:

plot "< awk '{ print NR-1,$0}' file.dat" matrix nonuniform using 1:3:2 with l pal z

will give you each line in a different colour e.g.

I think the animated gif question mentioned in title should be asked separately, but probably this question combined with the above will be sufficient for you to do it.

Solution 2:[2]

I am sure the OP already move to other things, but for anyone wondering if you manage to save the data in columns, so the first column are x-coordinates and columns 1,2....n are the according values each time step you can use

set terminal gif animate delay 10
set output 'solution.gif'
stats "file.txt" matrix nooutput

do for [i = 2:STATS_columns]{
    plot "file.txt" using 1:(column(i)) notitle with lines linestyle 1 
}
set output

to plot the data and make an animated gif.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Marhos