Philip Kearns
Philip Kearns

Reputation: 397

Setting xrange in gnuplot producing strange result

I was trying to use gnuplot to graph a CSV file containing date-time and temperature but it was producing some strange results when it worked (mainly just one line straight up in the middle of the graph). This is the code:

set xdata time
set timefmt '%Y-%m-%d %H:%M:%s'
set xrange["2013-05-29 00:00:00":"2013-06-04 00:00:00"]
set datafile separator ','
plot 'weather.csv' using 1:2

This is a sample of the data:

2013-05-29 18:30:00,20.0
2013-05-29 21:29:00,14.0
2013-05-29 22:29:00,13.0
2013-05-29 23:29:00,12.0
2013-05-30 08:28:00,13.0
2013-05-30 09:30:00,14.0

It was getting an error:

Can't plot with an empty x range!

So I typed the commands at the command line:

gnuplot> set xdata time
gnuplot> set timefmt '%Y-%m-%d %H:%M:%s'
gnuplot> set xrange["2013-05-29 00:00:00":"2013-06-04 00:00:00"]
gnuplot> show xrange

        set xdata time
        set xrange [ "1970-01-01 00:00:-946684800" : "1970-01-01 00:00:-946684800" ] noreverse nowriteback

gnuplot> show

What am I doing wrong?

Thanks

Upvotes: 0

Views: 4273

Answers (1)

Schorsch
Schorsch

Reputation: 7905

It's your timefmt definition.
According to this documentation, %s is interpreted as

seconds since the Unix epoch (1970-01-01 00:00 UTC)

This explains the output from your show xrange as well. For this date interpretation, your xrange will come up empty.

If you use %S (second, 0-60) instead, your example will plot fine:

set timefmt '%Y-%m-%d %H:%M:%S'

Upvotes: 2

Related Questions