Justin Patten
Justin Patten

Reputation: 1

How do I get gnuplot to read my time format and keep the times in order of the input file?

I'm trying to get gnuplot to (a) read my input time format and (b) plot the time in order of the input file. I'm trying to plot changes to a value over the past 24 hours starting at 18 UTC.

It doesn't appear to like:

set xdata time

set timefmt "%H%M"

It also likes to plot my xaxis values from 0000 UTC to 2300 UTC and drops leading zeros. See below for input file. I would like the newest data (1800UTC in this case) to be on the right side of my xaxis. Thanks.

1900 23

2000 22

2100 22

2200 22

2300 22

0000 22

0100 22

0200 21

0300 21

0400 21

0500 21

and so on...

Upvotes: 0

Views: 284

Answers (1)

theozh
theozh

Reputation: 26068

the suggestion from Michael O. to use a complete date with year, month, day is probably the most versatile way to handle your topic. However, if you cannot or don't want to change your data you could use the following:

Solution 1: add an extra day (or 86400 seconds) when data passes "0000"

Solution 2: use the first column as string label (x-axis will only be scaled correctly if your timesteps are constant). For fun, I added the possiblity to display only a part of the labels.

### time "without" date
reset session

$Data <<EOD
1900 23
2000 22
2100 22
2200 22
2300 22
0000 22
0100 22
0200 21
0300 21
0400 21
0500 21
EOD

set multiplot layout 2,1

    # solution 1: add extra day
    set xdata time
    set timefmt "%H%M"
    set format x "%H%M"
    extraday = 0
    plot $Data u ($1==0000 ? extraday = extraday + 1 : 0, timecolumn(1)+extraday*86400):2 w lp lt 7 lc rgb "red" title "add extra day"

    # solution 2: use timecolumn as xticlabel
    Modulo(x,n) = x - floor(x/n)*n
    plot $Data u 0:2:xticlabels(Modulo($1,200) == 0 ? stringcolumn(1) : "") w lp lt 7 lc rgb "green" title "timecolumn as xticlabel"

unset multiplot
### end of code

...will result in:

enter image description here

Upvotes: 1

Related Questions