0
votes

I want to plot two time series that are in different formats in the same format, but one of those two doesn't work for me.

So here's the thing:
I have a time series in seconds with a given starting time t0.

So the series looks like this:
Starting time: t0

0 -21.0028
5 -21.0067
10 -21.007
...
17875 -20.9943

I want to plot this time series with the time (e.g. 9:03) instead of seconds and I want to show another time series where the data is given in standard time in the same plot.

I can plot the second series just fine. But when I try to plot the first series, the measured points start jumping from x=100 back to 0 and then back and forth. Additionally I can't add the offset t0 to the series.

Here's what I tried (t0 = 32615s) to get at least the first time series plotted:

gnuplot> set xdata time
gnuplot> set timefmt "%S"
gnuplot> set format x "%H:%M"
gnuplot> plot 'measurement.dat' u (timecolumn(1)+32615):2 w l, 'measurement2.dat" u 1:2 w l

Does anyone know how I can plot these time series?

Thanks in advance!

1

1 Answers

0
votes

My understanding of your problem is that you have two data sets with different timedata. One in seconds and the other what you call "standard", I assume, e.g. 09:03:00. And you want to shift the one with seconds by some value. Internally, dates and times are stored as seconds from January 1st 1970 00:00:00. Since the first dataset is already in seconds just add your shift-value. You need to convert ´$Data2´ into seconds via timecolumn(1,"%H:%M:%S"). And the way you display the xtic labels is set via set format x "%H:%M" time. Also check help timecolumn. It also depends if you want to display a time of the day, i.e. 00:00 to 23:59 or if you want to display hours >24h. Then you might want to use "%tH:%tM:%tS"as format. Check help time_specifiers.

Code:

### shifted time data
reset session

# create some test data
set print $Data1
    do for [i=1:20000:200] {
        print sprintf("%d %.3f",i,sin(i/2000.))
    }
set print
set print $Data2
    do for [i=30000:50000:200] {
        print sprintf("%s %.3f",strftime("%H:%M:%S",i),2*sin(i/2000.-2.5))
    }
set print

set format x "%H:%M" time
set key top center

set multiplot layout 2,1
    plot $Data1 u 1:2 w lp ti "Data1", \
         $Data2 u (timecolumn(1,"%H:%M:%S")):2 w lp ti "Data2"

    t0 = 30000
    plot $Data1 u ($1+t0):2 w lp ti "shifted Data1", \
         $Data2 u (timecolumn(1,"%H:%M:%S")):2 w lp title "Data2"
unset multiplot
### end of code

Result:

enter image description here