-1

温度を測定するためにラズベリー パイを設置し、Gnuplot スクリプトを呼び出して Web ページにグラフを配置しました。

ここで、1 時間遡って表示するグラフと 1 日遡って表示するグラフをいくつか作成したいと考えています。

X範囲を「現在の時刻-1日」または「現在の時刻-1時間」に開始するように指定する方法を知っている人はいますか?

ありがとう!

4

2 に答える 2

0

私が使用したコードは次のとおりです。RasbianOSを搭載したRaspberryPiで実行しています。何か疑惑はありますか?ありがとう!

#!/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 に答える