簡體   English   中英

不同長度的 Gnuplot timefmt

[英]Gnuplot timefmt with different lengths

我嘗試從兩個 .csv 文件中提取 plot 某物。 第一個是時間格式 %Y-%m-%d %H:%M:%S,第二個是 %H:%M:%S。

我不可能同時顯示兩個圖表。 當我擦除“set timefmt/xrange“%Y-%m-%d %H:%M:%S””時,只顯示另一個圖表,反之亦然。

有人有想法,我能做什么?

文件一:

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

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

我的代碼:

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”讀取時間數據(未給出年份/日期),則時間被假定為相對於紀元日期 1-Jan-1970。 因此,這些數據點與 2022 年的數據點相差 52 年。

選項1:

如果兩個文件中的所有數據點都來自同一天,那么我建議最簡單的做法是跳過文件中存在的日期信息。 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"

字符串“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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM