Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble setting xrange when x is a time

477 views
Skip to first unread message

stuart.ke...@gmail.com

unread,
Sep 27, 2019, 9:23:31 AM9/27/19
to
BRIEF
I would like to pull a single day out of my multi-week data file. So I'm using 'set xrange'. But I'm stumbling on the format: gnuplot fails with
C:\Temp\Plot>gnuplot wst-a-rtr.gp
"wst-a-rtr.gp" line 32: Can't plot with an empty x range!

In the config file below, uncommenting either 'set xrange' line results in the above error. Leaving them both commented out results in a beautiful chart


DETAIL
Data File:
Date Time Transmitted Dropped
2019-09-13 05:21:56 44337071 524986
2019-09-13 05:25:01 44338275 524986
2019-09-13 05:30:02 44340129 524986
2019-09-13 05:35:01 44341967 524986
2019-09-13 05:40:02 44343952 525104
[...]


Config File:
# Define variables
long_title = 'COPP Drops across Time'
data_file = 'wst-a-rtr-log.txt'
output_file = 'wst-a-rtr.png'

# File specifics
set datafile sep whitespace
set output output_file

# Chart details
set title long_title font 'sans,30'
set terminal png size 3200,1200
set grid
set xlabel "Date\nTime" font 'sans,18'
#set xrange [ "2019-09-25" : "2019-09-26" ]
#set xrange [ "2019-09-26 00:00" : "2019-09-27 06:00" ]
set ylabel 'Bytes Transmitted' textcolor '#3CB371' font 'sans,18'
set y2label 'Bytes Dropped' textcolor 'red' font 'sans,18'
set ytics border nomirror textcolor '#3CB371'
set y2tics border nomirror textcolor 'red'
set autoscale y
set autoscale y2

# Time formatting
set xdata time
set timefmt "%Y-%m-%d\t%H:%M"
set format x "%Y-%m-%d\n%H:%M"
set mxtics 24
set grid mxtics

# Do the work
plot data_file index 0 using 1:3 axis x1y1 with points pointtype 7 pointsize 1 linecolor rgb '#3CB371' title '', \
'' using 1:4 axis x1y2 with points pointtype 7 pointsize 1 linecolor rgb 'red' title ''

Karl Ratzsch

unread,
Sep 27, 2019, 5:44:44 PM9/27/19
to
Am 27.09.2019 um 15:23 schrieb stuart.ke...@gmail.com:
> I would like to pull a single day out of my multi-week data file. So I'm using 'set xrange'. But I'm stumbling on the format: gnuplot fails with
> C:\Temp\Plot>gnuplot wst-a-rtr.gp
> "wst-a-rtr.gp" line 32: Can't plot with an empty x range!
>

> set xrange [ "2019-09-25" : "2019-09-26" ]


Type "show xrange" after this, and you see it didnt work. "set
xrange" does not understand formatted time data. Maybe it should
give an error message here. E.g.

print "2019-09-25" + 1

gives

2020.0

gnuplots string autopromotion is perhaps a bit too ambitious here. ;)

You need to transform those strings into a unix date, check the
strptime() function.

Karl

Hans-Bernhard Bröker

unread,
Sep 28, 2019, 9:24:00 AM9/28/19
to
Am 27.09.2019 um 23:44 schrieb Karl Ratzsch:
> Am 27.09.2019 um 15:23 schrieb stuart.ke...@gmail.com:

>> set xrange [ "2019-09-25" : "2019-09-26" ]

> Type "show xrange" after this, and you see it didnt work. "set
> xrange" does not understand formatted time data.

That's not quite as true as you make it out to be. It can understand
time/date strings, but you have to tell it to:

gnuplot> set xdata time
gnuplot> set timefmt '%Y-%m-%d'
gnuplot> set xrange ['2019-02-07':'2020-03-31']
gnuplot> show xrange

set xdata time
set xrange [ "2019-02-07" : "2020-03-31" ] noreverse nowriteback

stuart.ke...@gmail.com

unread,
Sep 30, 2019, 7:19:30 AM9/30/19
to
I have fixed this

My error was to place the 'set xrange' ahead of 'set timefmt'

Fails:
set xrange [ '2019-09-26 00:00' : '2019-09-27 06:00' ]
set xdata time
set timefmt "%Y-%m-%d\t%H:%M"

Succeeds:
set xdata time
set timefmt "%Y-%m-%d\t%H:%M"
set xrange [ '2019-09-26 00:00' : '2019-09-27 06:00' ]

--sk
0 new messages