简体   繁体   English

不同长度的 Gnuplot timefmt

[英]Gnuplot timefmt with different lengths

I try to plot sth out of two.csv files.我尝试从两个 .csv 文件中提取 plot 某物。 In the first there is the timeformat %Y-%m-%d %H:%M:%S and in the second %H:%M:%S.第一个是时间格式 %Y-%m-%d %H:%M:%S,第二个是 %H:%M:%S。

It isn't possible for me, to show both graphs at once.我不可能同时显示两个图表。 When i erase the "set timefmt/xrange "%Y-%m-%d %H:%M:%S"", only the other graph is showed and the other way around.当我擦除“set timefmt/xrange“%Y-%m-%d %H:%M:%S””时,只显示另一个图表,反之亦然。

Somebody have an idea, what I can do?有人有想法,我能做什么?

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:文件2:

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
...

My code:我的代码:

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

My code:我的代码:

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

I think the problem is that only one of your data files gives a specific date.我认为问题在于您的数据文件中只有一个给出了具体日期。

If you read in time data using format "%H:%M:%S" (no year/date given) then the times are assumed to be relative to the epoch date 1-Jan-1970.如果您使用格式“%H:%M:%S”读取时间数据(未给出年份/日期),则时间被假定为相对于纪元日期 1-Jan-1970。 So those data points come out 52 years off from the 2022 data points.因此,这些数据点与 2022 年的数据点相差 52 年。

Option 1:选项1:

If all the data points in both files are from the same day, then I suggest the easiest thing to do is skip the date information in the file where it is present.如果两个文件中的所有数据点都来自同一天,那么我建议最简单的做法是跳过文件中存在的日期信息。 Ie IE

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"

The string "2022-11-24" must match on input for the first file but it doesn't actually contribute to the date calculation.字符串“2022-11-24”必须与第一个文件的输入相匹配,但它实际上不会影响日期计算。

Option 2 :选项 2

If you really do care about the date, or if the first file spans multiple dates so that a constant string cannot match, then you could instead add a date component to the time string in the second file by concatenating a string constant containing the date.如果您确实关心日期,或者如果第一个文件跨越多个日期以致常量字符串无法匹配,那么您可以通过连接包含日期的字符串常量来将日期组件添加到第二个文件中的时间字符串。

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM