|
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 ""
|
|
From: hchiPer <hc...@gm...> - 2024-04-18 18:41:33
|
I've copied pasted your example and it is not working (error message =
line 39: all points y value undefined!)
I could make it work with the following modifications:
- remove the 3 tabs and leave just 1 in the data file
- change the time format:
set timefmt "%H:%M:%S" ### instead of set timefmt "%Y-%m-%d\t%H:%M:%S"
- remove the 2 system calls
- change the xrange:
set xrange ["00:00:00":"23:59:59"]
- use column 2 instead of column 1 in the plot command:
plot "./x.txt" using 2:3:(rgb3($3)) with line lw 1 lc rgb variable
notitle
Le 14/04/24 à 11:13, Lars Noodén via gnuplot-info a écrit :
>
> 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 ""
>
>
>
> _______________________________________________
> gnuplot-info mailing list
> gnu...@li...
> Membership management via:
> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
|
|
From: Lars N. <lar...@gm...> - 2024-04-19 07:29:21
|
On 4/18/24 21:41, hchiPer wrote: [snip] > - change the time format: > > set timefmt "%H:%M:%S" > ### instead of set timefmt "%Y-%m-%d\t%H:%M:%S" Thanks! That was the key to solving this. [snip] > set xrange ["00:00:00":"23:59:59"] > > - use column 2 instead of column 1 in the plot command: [snip] And with that, I can remove the system calls and still get a chart from midnight to midnight. /Lars |