Skip to content Skip to sidebar Skip to footer

Plotting Multiple (x,y) Co-ordinates In A Single Curve With Gnuplot

Hi I want to plot multiple (x,y) coordinates in a single graph. Say I have a data file which has the contents like the following: x y 0.0 0.5 0.12 0.1 0.16 0.4 0.2

Solution 1:

gnuplot can only plot column format data as far as I know. That said, you will have to plot it in after transpose your data as follows:

x  0.000000 y  0.500000 x  0.120000 y  0.100000  ...
x1 0.040000 y1 0.700000 x1 0.080000 y1 0.740000  ...

and plot data us 1:2, data us 3:4, data us 5:6.

To transpose the data, you can either change your program to write it in this way, or use following awk script:

awk '{for (i=1;i<=NF;i++) arr[NR,i]=$i;} END{for (i=1;i<=NF;i=i+2) {for (j=1;j<=NR;j++) {printf "%f %f ",arr[j,i],arr[j,i+1]} print ""}}' datafile

Post a Comment for "Plotting Multiple (x,y) Co-ordinates In A Single Curve With Gnuplot"