在gnuplot xaxis上混合日期和时间 [英] mixing date and time on gnuplot xaxis

查看:76
本文介绍了在gnuplot xaxis上混合日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在x轴上绘制一天中的小时数,但是要打印一天从一天到另一天的日期.因此,x轴可能看起来像这样:

I'd like to plot hours of the day on the x axis, but print the date when the day rolls over from one day to the next. So the x axis might look like this:

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

在gnuplot中有一种明智的方法吗?

Is there a sane way to do this in gnuplot?

FWIW,我的文件当前看起来像这样:

FWIW, my file currently looks something like this:

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

推荐答案

这很困难,让我想了一下.这是您的操作方法:

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

您需要将x轴的格式设置为%H:%M,然后将00:00替换为日期,类似于完成在这个答案中.

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.

然后主要工作是提取深夜的时间戳.为此,我使用了stats命令(至少需要版本4.6.0),但是由于它不支持时间数据,因此您必须使用strptime或类似的东西来摆弄一下:

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

我将num_days增加了2,以说明x范围可能自动扩展到下一个抽动.

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

与您的数据一起得出的结果是(使用4.6.4):

The result with your data is (with 4.6.4):

这篇关于在gnuplot xaxis上混合日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆