绘制多个(x,y)与gnuplot在一条曲线上的坐标。

时间:2021-06-01 22:46:23

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)坐标。假设我有一个数据文件,它包含如下内容:

 x      y
0.0    0.5
0.12   0.1
0.16   0.4
0.2    0.35
0.31   0.8
0.34   0.6
0.38   1.0
0.46   0.2
0.51   0.7
0.7    0.9

could I have a some more data in this file like,

我能在这个文件里多放一些数据吗,

 x     y       x1     y1
0.0    0.5    0.04    0.7   
0.12   0.1    0.08    0.74 
0.16   0.4    0.12    0.85
0.2    0.35   0.16    0.9
0.31   0.8    0.2     0.53
0.34   0.6    0.24    0.31
0.38   1.0    0.28    0.87
0.46   0.2    0.32    0.20
0.51   0.7    0.36    0.45
0.7    0.9    0.4     0.64

and plot the graph on gnuplot where (x,y) and (x1,y1) would all be in a single curve? Thank you.

在gnuplot上绘制图形(x,y)和(x1,y1)都在一条曲线上?谢谢你!

1 个解决方案

#1


2  

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:

就我所知,gnuplot只能绘制列格式数据。也就是说,你需要在转置后将数据绘制成:

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.

而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脚本:

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

#1


2  

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:

就我所知,gnuplot只能绘制列格式数据。也就是说,你需要在转置后将数据绘制成:

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.

而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脚本:

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