在gnuplot中,如何将两个不同文件中的数据绘制到一个绘图中?

在gnuplot中,如何将两个不同文件中的数据绘制到一个绘图中?,gnuplot,Gnuplot,我有两个不同的文件要在gnuplot中绘制。它们使用a)不同的分隔符b)x轴上的不同时间 因此,对于它们中的每一个单独绘制,我需要通过 set datafile separator set timefmt 我想将这两个数据合并/叠加在一个图表中,以便它们与时间对齐 我怎样才能做到这一点呢?你说得对,你需要为每个文件传递一次设置数据文件分隔符和设置timemt。您可以这样做: set terminal <whatever> set output <whatever.wht>

我有两个不同的文件要在gnuplot中绘制。它们使用a)不同的分隔符b)x轴上的不同时间

因此,对于它们中的每一个单独绘制,我需要通过

set datafile separator
set timefmt
我想将这两个数据合并/叠加在一个图表中,以便它们与时间对齐


我怎样才能做到这一点呢?

你说得对,你需要为每个文件传递一次
设置数据文件分隔符
设置timemt
。您可以这样做:

set terminal <whatever>
set output <whatever.wht>

set xdata time             # tell gnuplot to parse x data as time
set format x '%F'          # time format to display on plot x axis

set datafile separator ' ' # separator 1
set timefmt '%F'           # time format 1
plot 'file1'

set datafile separator ',' # separator 2
set timefmt '%s'           # time format 2
replot 'file2'
设置终端
设定输出
设置扩展数据时间#告诉gnuplot将x数据解析为时间
将格式x“%F”#时间格式设置为显示在绘图x轴上
设置数据文件分隔符“”#分隔符1
设置timemt“%F”#时间格式1
打印“文件1”
设置数据文件分隔符“,”#分隔符2
设置timemt“%s”#时间格式2
回复“文件2”

replot
命令本身会重新打印上一行,如果您指定要打印的另一行,它将位于第一行的顶部,就像我在这里所做的那样。

在我看来,您有两个选项。第一种方法是选择一种数据文件格式并将两种数据文件转换成该格式,可以使用
awk

plot '<awk "-f;" "{print $1,$2}" data1' using 1:2 w lines,\
     'data2' using 1:2 w lines

绘图
NaN
技巧只有在您希望在图例中正确显示内容时才有必要。如果您不使用图例,则不必担心它。

可以通过使用“使用”修改器后的格式为每个文件指定不同的分隔符来解决不同分隔符的问题,例如:

plot 'file1.dat' u 1:2 '%lf,%lf'
使用逗号分隔符打印两列文件。有关更多详细信息,请参阅帮助\使用

我不是时间格式专家,所以我不知道如何处理时间戳格式问题。但也许您可以使用一些函数,如
strftime()
。我从未尝试过,但在我看来,它能满足你的需要。

这对我很有用:

reset 
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid

set label "(Disabled)" at -.8, 1.8
plot  "file1.csv" using 1:2 ls 1 title "one" with lines ,\
  "file2.csv" using 1:2 ls 2 title "two" with lines ,\
  "file3.csv" using 1:2 ls 3 title "three" with lines
set output

这似乎不起作用,因为
replot
将在上一个命令中重新读取文件,但现在数据文件分隔符不正确,因此gnuplot将找不到任何点(或者至少找不到正确的点)。大家好,感谢回复。最后,我做了一个小型python包装器,它接受我的数据并将它们转换成另一种格式。这允许使用单点打印命令,自动对齐轴。上面的技巧也可以使用,我想如果两个数据源都“不可使用”,就必须使用。如果时间数据中没有空格(或相应的列分隔符),strftime()将起作用。自gnuplot 5.0以来,timecolumn()函数接受额外的单个格式字符串
reset 
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid

set label "(Disabled)" at -.8, 1.8
plot  "file1.csv" using 1:2 ls 1 title "one" with lines ,\
  "file2.csv" using 1:2 ls 2 title "two" with lines ,\
  "file3.csv" using 1:2 ls 3 title "three" with lines
set output