2

x 軸に 1 日の時間をプロットしたいのですが、ある日から次の日に変わる日付を出力します。したがって、x 軸は次のようになります。

11/02 04:00 08:00 12:00 16:00 20:00 11/03 04:00 08:00 ...

gnuplot でこれを行う適切な方法はありますか?

FWIW、私のファイルは現在次のようになっています。

set xdata time
set timefmt "%Y-%m-%d|%H:%M:%S"
plot '-' using 1:2 with lines linewidth 1 linecolor rgb "#FF0000"
2013-11-02|00:00:48 123.0
2013-11-02|00:00:55 124.0
2013-11-02|00:01:06 121.0
2013-11-02:00:01:17 123.0
...
2013-11-04|23:59:41 241.0
2013-11-04|23:59:52 241.0
4

2 に答える 2

3

That is a tough one, made me think a bit. Here is how you can do it:

You need to set the format of the x-axis to %H:%M and then replace the 00:00 with dates, similarly like done in this answer.

The main work is then to extract the timestamps for the mid nights. I use the stats command for this (needs at least version 4.6.0), but because it doesn't support time data you must fiddle around a bit with strptime and similar:

fmt = "%Y-%m-%d|%H:%M:%S"
stats 'file.txt' using (strptime(fmt, stringcolumn(1))) nooutput
t = int(STATS_min)
t_start = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
num_days = 2 + (int(STATS_max) - t)/(24*60*60)

set xdata time
set timefmt fmt
set xtics 4*60*60
set for [i=1:num_days] xtics add (strftime('%m/%d', t_start+(i-1)*24*60*60) t_start+(i-1)*24*60*60)
set format x '%H:%M'
plot 'file.txt' using 1:2 with lines

I increment num_days by 2 to account for the possible automatic extension of the x-range to the next tics.

The result with your data is (with 4.6.4):

enter image description here

于 2013-11-09T22:10:05.573 に答える