-1

我已经建立了一个树莓派来测量温度并调用一个 Gnuplot 脚本在网页上放置一个图表。

现在我想制作几个图表,显示时间倒退 1 小时/时间倒退 1 天。

有谁知道我如何指定 X 范围从“当前时间 - 1 天”或“当前时间 - 1 小时”开始?

谢谢!

4

2 回答 2

0

我使用的代码如下。我在带有 Rasbian OS 的 Raspberry Pi 上运行它。有什么建议吗?谢谢!

#!/usr/bin/gnuplot
reset
set terminal png size 1250,700
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#E6E6FA" behind

set output '/var/www/bild.png'
set multiplot

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%H:%M\n%d/%m"
set xlabel "Timme/datum"

set ylabel "Inomhustemperatur"
set yrange [15:28]

set y2label "Utomhustemperatur"
set y2range [-20:10]
set y2tics nomirror
set y2tics

set title "Temperatur"
set key reverse Left outside
set grid

set style data lines

plot "logg.txt" using 1:3 axes x1y1 lw 3 title "inomhus", "" using 1:4 axes x1y2 lw 3   title "utomhus"#
于 2013-01-25T16:28:28.900 回答
0

这不适用于任何地方,但是如果您的 gnuplot 支持管道并且您的系统具有date命令...

TIMEFMT = "%Y:%m:%d:%H:%M:%S"
#now = "`date +%Y:%m:%d:%H:%M:%S`"  #Use this line in production
now = '2013:01:24:20:49:30'  #Hard-code this for the sake of the example ...
now_secs = strptime(TIMEFMT,now)
one_hour_past = now_secs - 3600.0

set xdata time
#set timefmt TIMEFMT  #This doesn't parse correctly ... Not sure why...
eval(sprintf('set timefmt "%s"',TIMEFMT))

print strftime(TIMEFMT,one_hour_past)

#set xrange [strftime(TIMEFMT,one_hour_past):]  #This doesn't seem to work
#set xrange ["2013:01:24:20:49:30":]            #This works, but is declared statically -- Yuck.
eval(sprintf('set xrange ["%s":]',strftime(TIMEFMT,one_hour_past)))

plot '-' u 1:2 w l
   2013:01:24:10:00:00 2.5
   2013:01:24:21:00:00 2
   2013:01:24:22:00:00 3
   e
于 2013-01-25T02:35:42.190 回答