不同长度的Gnuplot timefmt



我试着从两个。csv文件中画出一些东西。第一个时间格式为%Y-%m-%d %H:% m:%S,第二个时间格式为%H:% m:%S。

我不可能同时显示两个图表。当我擦除&;set timefmt/xrange &;%Y-%m-%d %H:% m:% s&; &;时,只显示另一个图形,反之则显示另一个图形。

有人知道我该怎么做吗?

File1:

1;2022-11-24 17:21:34;0;+3.311;+0.004;+0.003;+0.001;+0.000;+0.000;+0.000;+0.000;+0.001;-0.001;+0.001;+0.000;-0.001;+0.000;-0.001;+0.000;+0.000;-0.001;+0.002;-0.001;LLLLLLLLLL;LLLLLLLLLL;LLLLLLLLL
2;2022-11-24 17:21:34;200;+3.311;+0.007;+0.002;+0.001;-0.001;+0.000;+0.000;-0.001;+0.001;-0.001;+0.001;+0.000;-0.002;+0.001;-0.001;+0.000;+0.001;-0.001;+0.001;-0.001;LLLLLLLLLL;LLLLLLLLLL;LLLLLLLLL
...

File2:

17:22:28;3.446;1.398;0.007;4.817508;0.025
17:22:29;3.447;1.398;0.008;4.818906;0.027
17:22:30;3.448;1.398;0.008;4.820303999999999;0.029
...

我代码:

set grid
set datafile separator ";"
set title 'xxx'
set title font ",12"
set ylabel 'U/V' font ",12"
#set format x "%H:%M:%S"
set key box font ",12"
#myformat = "%Y-%m-%d %H:%M:%S"
#set key at strptime(myformat,"2022-11-24 18:02:55"), 3.005
set xtics time
set xlabel 'time' font ",12"
set yrange [3:3.7]
set ytics font ",10"
set y2tics font ",10"
set border 11
set border lw 2
set xtics font ",8"
set tics nomirror
set term wxt size 1200, 460
set xdata time
**#set timefmt "%Y-%m-%d %H:%M:%S"
set timefmt "%H:%M:%S"
#set xrange ["2022-11-24 17:22:00":"2022-11-24 18:47:00"]
set xrange ["17:20:00":"18:47:00"]**
plot'xxx.CSV' using (timecolumn(2, "%Y-%m-%d %H:%M:%S")):4 every ::43::25741 title "aaa" lt 7 lc 7 with lines, 
'yyy.csv' using (timecolumn(1, "%H:%M:%S")):2 title "bbb" lt 3 lc 6 with lines

我代码:

set grid
set datafile separator ";"
set title 'xxx'
set title font ",12"
set ylabel 'U/V' font ",12"
#set format x "%H:%M:%S"
set key box font ",12"
#myformat = "%Y-%m-%d %H:%M:%S"
#set key at strptime(myformat,"2022-11-24 18:02:55"), 3.005
set xtics time
set xlabel 'time' font ",12"
set yrange [3:3.7]
set ytics font ",10"
set y2tics font ",10"
set border 11
set border lw 2
set xtics font ",8"
set tics nomirror
set term wxt size 1200, 460
set xdata time
**#set timefmt "%Y-%m-%d %H:%M:%S"
set timefmt "%H:%M:%S"
#set xrange ["2022-11-24 17:22:00":"2022-11-24 18:47:00"]
set xrange ["17:20:00":"18:47:00"]**
plot'xxx.CSV' using (timecolumn(2, "%Y-%m-%d %H:%M:%S")):4 every ::43::25741 title "aaa" lt 7 lc 7 with lines, 
'yyy.csv' using (timecolumn(1, "%H:%M:%S")):2 title "bbb" lt 3 lc 6 with lines

我认为问题是你的数据文件中只有一个给出了具体的日期。

如果您使用格式"%H:%M:%S"读取实时数据(没有给出年份/日期),则假定时间相对于1970年1月1日的历元日期。所以这些数据点比2022年的数据点差了52年。

选项1:

如果两个文件中的所有数据点都来自同一天,那么我建议最简单的方法是跳过文件中存在的日期信息。例如

set timefmt "%H:%M:%S"
set xrange ["17:20:00":"18:47:00"]
plot 'xxx.csv' using (timecolumn(2, "2022-11-24 %H:%M:%S")):4 title "aaa" 
'yyy.csv' using (timecolumn(1, "%H:%M:%S")):2 title "bbb"

字符串"2022-11-24"必须匹配第一个文件的输入,但它实际上对日期计算没有贡献。

选项2:

如果你真的关心日期,或者如果第一个文件跨越多个日期,以至于一个常量字符串无法匹配,那么你可以通过连接一个包含日期的字符串常量,在第二个文件的时间字符串中添加一个日期组件。

myfmt = "%Y-%m-%d %H:%M:%S"
set timefmt "%Y-%m-%d %H:%M:%S"
set xrange ["2022-11-24 17:20:00":"2022-11-24 18:47:00"]
plot 'xxx.csv' using (timecolumn(2, myfmt)):4 title "aaa" lt 7 lc 7 with lp, 
'yyy.csv' using (strptime(myfmt,"2022-11-24 ".strcol(1))):2 title "bbb" lt 3 lc 6 with lp 

相关内容

  • 没有找到相关文章

最新更新