Gnuplot 绘制两个具有不同时间格式的数据

Gnuplot plot two data with different time format

我有两个时间格式不同的数据:
文件 1(%Y %j %H %M %S 级别):

2011 170 0 0 0 0.017042
2011 170 0 30 0 0.002124
2011 170 1 0 0 0.061001
2011 170 1 30 0 0.096256
2011 170 2 0 0 0.073920
2011 170 2 30 0 0.048899
2011 170 3 0 0 0.039534
2011 170 3 30 0 0.044790
2011 170 4 0 0 0.052662
2011 170 4 30 0 0.063144
etc ...

file2(%Y %m %d %H %M潮):

2011 06 19 00 00 2.1950
2011 06 19 00 05 2.2650
2011 06 19 00 10 2.3290
2011 06 19 00 15 2.4030
2011 06 19 00 20 2.4730
2011 06 19 00 25 2.5480
2011 06 19 00 30 2.6220
2011 06 19 00 35 2.6890
2011 06 19 00 40 2.7690
2011 06 19 00 45 2.8460
2011 06 19 00 50 2.8970
2011 06 19 00 55 2.9690
2011 06 19 01 00 3.0610
2011 06 19 01 05 3.1370
2011 06 19 01 10 3.2030
2011 06 19 01 15 3.2670
etc ...

是否可以在同一张图中绘制这些数据?如果可以,怎么做?

我做的是:

set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
plot "./file1" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2" u 1:6 w lines ls 3 lc rgb "black" notitle axes x1y2

结果好像不太对
任何帮助将不胜感激。
谢谢

您必须手动解析第二个文件的时间。在 gnuplot 5.0 中,这非常方便,因为您可以简单地给 timecolumn 一个时间格式作为第二个选项。然后它使用这种格式而不是 set timefmt:

给出的格式
set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
set y2tics
set ytics nomirror
plot "./file1.txt" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2.txt" u (timecolumn(1, "%Y %m %d %H %M")):6 w lines ls 3 lc rgb "black" notitle axes x1y2

在早期的 gnuplot 版本中,您必须首先构造一个包含所有时间信息的字符串,然后使用 strptime:

解析该字符串
set xdata time
set timefmt "%Y %j %H %M %S"
set xtics "2011 170 0 0 0",43200, "2011 172 0 0 0"
set xrange ["2011 170 0 0 0":"2011 172 0 0 0"]
set xtics format "%j"
set y2tics
set ytics nomirror
mytimecolumn(c, fmt) = strptime(fmt, sprintf('%s %s %s %s %s', strcol(c), strcol(c+1), strcol(c+2), strcol(c+3), strcol(c+4)))
plot "./file1.txt" u 1:6 w lines ls 3 lc rgb "dark-red" notitle, \
"./file2.txt" u (mytimecolumn(1, "%Y %m %d %H %M")):6 w lines ls 3 lc rgb "black" notitle axes x1y2