Search code examples
csvplotgnuplot

Gnuplot timecolumn with few measurements. One data with "day overflow"


I did a few measurements for discharging batteries. Now i wanted to plot them with Gnuplot. The problem is, that one of the measurements startet very late, that I have an "overflow" from my 24hours-clock.

Here an example of my problem-.csv-measurement data:

Time;Voltage;Current;Charge;Power;Energy;Temperature
...
23:59:54;3.2387;0.6989;0.039;2.264;0.127;22.0
23:59:55;3.2387;0.6989;0.039;2.264;0.128;22.0
23:59:56;3.2387;0.6989;0.039;2.264;0.129;22.0
23:59:57;3.2387;0.6989;0.04;2.264;0.129;22.0
23:59:58;3.2387;0.6992;0.04;2.264;0.13;22.0
23:59:59;3.2386;0.6989;0.04;2.263;0.13;22.0
00:00:00;3.2386;0.6992;0.04;2.264;0.131;22.0
00:00:01;3.2386;0.6989;0.04;2.263;0.132;22.0
00:00:02;3.2386;0.6992;0.041;2.264;0.132;22.0
00:00:04;3.2386;0.6992;0.041;2.264;0.133;22.5
00:00:05;3.2386;0.6989;0.041;2.263;0.134;22.5
00:00:06;3.2386;0.6989;0.041;2.263;0.134;22.5
00:00:07;3.2386;0.6989;0.041;2.263;0.135;22.0

the other datas dont measured between two days.

With the following Gnuplot-code:

set grid
set title 'Entladungen der Batterie über Zeit'
set tics nomirror
set title font ",12"
set ylabel 'U/V' font ",12"
set key box font ",12"
set xtics time
set xlabel 'time' font ",12"
set border 11
set border lw 2
set xtics font ",8"
set term wxt size 1200, 460
myFmt = "%H:%M:%S"
set datafile separator ";"
set format x "%tH:%M:%S" #timedate
set yrange[2.6:3.7]

plot 'Entadung_4,2A_Temp_22,5C°.csv' u (t=timecolumn(1,myFmt), $0==0?t01=t:0, t-t01):2 every ::2::1061 lt 7 lc "blue" with lines      ti "Entladung bei 3C", \
     'Entadung_2,8A_Temp_22,5C°.csv' u (t=timecolumn(1,myFmt), $0==0?t02=t:0, t-t02):2 every ::2::1604 lt 7 lc "web-green" with lines ti "Entladung bei 2C", \
     'Entadung_1,4A_Temp_22,0C°.csv' u (t=timecolumn(1,myFmt), $0==0?t03=t:0, t-t03):2 every ::2::3267 lt 7 lc "red" with lines      ti "Entladung bei 1C",\
     'Entadung_0,7A_Temp_22,0C°.csv' u (t=timecolumn(1,myFmt), $0==0?t04=t:0, t-t04):2 every ::2::6696 lt 7 lc "yellow" with lines ti "Entladung bei 0,5C", \
     'Entadung_0,28A_Temp_22,0C°.csv' u (t=timecolumn(1,myFmt), $0==0?t05=t:0, t-t05):2 every ::2::16977 lt 7 lc "black" with lines      ti "Entladung bei 0,2C",\
     'Entadung_0,14A_Temp_22,5C°.csv' u (t=timecolumn(1,myFmt), $0==0?t06=t:0, t-t06):2 every ::2::33731 lt 7 lc "violet" with lines      ti "Entladung bei 0,1C"

I got this output:

Output

The plot takes the 23 hours and subtract ist from every timestep. So i get negative time...

Anybody know, how i can use an offset just for this one data, that the others stay untouched?

I was expecting, that the yellow graph lays between the red and the black graph.


Solution

  • Unfortunately, you don't record the date as well. If you had you wouldn't have this problem.

    But you can account for midnight crossings with a little addition.

    • assign t1=NaN and td=0 before the plot command
    • within the plot command (loop), assign t0=t1 and directly afterwards t1=timecolumn(...). So, t0 always holds the previous value and t1 the current value
    • every time t1<t0 (i.e. crossing midnight) add one day to td, i.e. td=td+secsPerDay (number of seconds per day) and add td to your plotting value.
    • furthermore, if you use %tH as x-timeformat, hours will not wrap at 24 hours, in case your measurement runs for longer than 24 hours (check help time_specifiers).

    Script:

    ### account for midnight crossings
    reset session
    
    $Data <<EOD
    23:59:00   3.7
    01:59:00   3.6
    12:00:00   3.5
    23:00:00   3.4
    02:30:00   3.3
    13:00:00   3.2
    23:00:00   3.1
    03:00:00   3.0
    14:00:00   2.9
    EOD
    
    myFmt = "%H:%M:%S"
    secsPerDay = 3600*24
    
    set xlabel "hours:min"
    set format x "%tH:%M" timedate
    
    set multiplot layout 2,1
    
        plot $Data u (t=timecolumn(1,myFmt), $0==0? t01=t:0, t-t01):2 w lp pt 7 lc "red" ti "as is"
        
        plot t1=(td=0,NaN) $Data u (t0=t1,t1=timecolumn(1,myFmt), $0==0? t01=t1:0, \
             t1<t0?td=td+secsPerDay:0, t1-t01+td):2 w lp pt 7 lc "blue" ti "add day offset"
        
    unset multiplot
    ### end of script
    

    Result:

    enter image description here