|
From: Lars N. <lar...@gm...> - 2024-04-14 09:13:33
|
Greetings,
Thanks for Gnuplot. I've been using it to graph various sensor
readings for some years now. From time to time, it becomes useful to
make modifications and between the documentation, various examples, and
trial-and-error the results look nice in addition to being functional.
My question is how would I set X-Range to be the time from 00:00:00 to
23:59:59 on the current date? Specifically, I would like the X-axis to
range from midnight to midnight for the current date.
I can't hard code it in to Gnuplot since, obviously, the date changes
every day. Also since the data to be graphed comes in at different
times during the day, using it provides an inconsistent X-Range which
changes as the hours go by. So that can't be used either.
One way seems to be to use system() to call the date(1) utility twice
and storing output in variables. This is seen in lines 25 through 27 of
the script below.
Perhaps there is a better way without needing to use the system() call?
/Lars
PS. The file x.txt has three tab-delimited columns. e.g.
2024-04-14 10:40:00 20.375
2024-04-14 10:50:00 20.375
2024-04-14 11:00:00 20.437
2024-04-14 11:10:00 20.5
2024-04-14 11:20:00 20.5
--
#!/usr/bin/gnuplot
set output "./x.png"
set term png size 400, 400
set term png background "#fff0f0f0"
set termoption font "Liberation Sans, 12"
set datafile separator tab
set xdata time
set timefmt "%Y-%m-%d\t%H:%M:%S"
set xtics format "%H" font "Liberation Sans, 11"
set xtics timedate
# draw line at zero
set arrow 1 from graph 0, first 0.0 to graph 1, \
first 0.0 nohead lw 2 lc rgb "#e0e0e0" back
set ytics format "%0.0f°" font "Liberation Sans, 11"
set yrange [*<-5:30<*] writeback
# set yrange restore
xs=system("date -d '00:00:00' +'%F\t%T'")
xe=system("date -d '23:59:59' +'%F\t%T'")
set xrange [xs:xe]
set xlabel "Time" font "Liberation Sans, 14"
set ylabel "Degrees Celsius" font "Liberation Sans, 14"
set title "Since Midnight" font "Liberation Sans, 16"
# probe 1, change color when at or below 15°C
rgb3(b) = (b <= 15 ? 32767 : 65280 )
plot \
"./x.txt" \
using 1:3:(rgb3($3)) \
with line lw 1 lc rgb variable \
title ""
|