Home > Mobile >  Gnuplot timefmt with different lengths
Gnuplot timefmt with different lengths

Time:11-27

I try to plot sth out of two .csv files. In the first there is the timeformat %Y-%m-%d %H:%M:%S and in the second %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.

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:

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

CodePudding user response:

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. So those data points come out 52 years off from the 2022 data points.

Option 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. I.e.

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.

Option 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 
  • Related