gnuplot xaxis上的混合日期和时间
我想在x轴上绘制一天中的小时数,但打印一天从一天滚动到下一天的日期。因此,x轴可能如下所示:gnuplot xaxis上的混合日期和时间,gnuplot,Gnuplot,我想在x轴上绘制一天中的小时数,但打印一天从一天滚动到下一天的日期。因此,x轴可能如下所示: 11/02 04:00 08:00 12:00 16:00 20:00 11/03 04:00 08:00 ... 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 04:00 08:00 12:00 16:00 20:00 11/03 04:00 08:00 ...
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
在gnuplot中有没有一种明智的方法来实现这一点
FWIW,我的文件当前看起来像这样:
11/02 04:00 08:00 12:00 16:00 20:00 11/03 04:00 08:00 ...
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
这很难,让我想了想。以下是您如何做到这一点: 您需要将x轴的格式设置为
%H:%M
,然后用日期替换00:00
,类似于完成
然后,主要工作是提取午夜的时间戳。为此,我使用了stats
命令(至少需要4.6.0版),但由于它不支持时间数据,因此您必须使用strtime
和类似的命令进行处理:
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按2
增加num_days
,以说明x范围可能自动扩展到下一个TIC
您的数据结果如下(见4.6.4):
这是一个困难的问题,让我思考了一下。以下是您如何做到这一点: 您需要将x轴的格式设置为
%H:%M
,然后用日期替换00:00
,类似于完成
然后,主要工作是提取午夜的时间戳。为此,我使用了stats
命令(至少需要4.6.0版),但由于它不支持时间数据,因此您必须使用strtime
和类似的命令进行处理:
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按2
增加num_days
,以说明x范围可能自动扩展到下一个TIC
您的数据结果如下(见4.6.4):
这是一个带有
xticlabels
的版本:
$data <<EOD
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
EOD
set xdata time
set timefmt "%Y-%m-%d|%H:%M:%S"
plot $data using 1:2 w l # plot to get GPVAL_X_MIN GPVAL_X_MAX
t = GPVAL_X_MIN
t_start = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
num_days = 1 + (GPVAL_X_MAX-GPVAL_X_MIN)/(24*60*60)
replot [i=0:6*num_days:1] '+' us (t=t_start+i*24*60*60/6, strftime('%Y-%m-%d|%H:%M:%S', t)):(NaN):xtic(strftime(int(i)%6?'%H:%M':'%m-%d',t)) t ""
$data这是一个带有xticlabels
的版本:
$data <<EOD
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
EOD
set xdata time
set timefmt "%Y-%m-%d|%H:%M:%S"
plot $data using 1:2 w l # plot to get GPVAL_X_MIN GPVAL_X_MAX
t = GPVAL_X_MIN
t_start = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
num_days = 1 + (GPVAL_X_MAX-GPVAL_X_MIN)/(24*60*60)
replot [i=0:6*num_days:1] '+' us (t=t_start+i*24*60*60/6, strftime('%Y-%m-%d|%H:%M:%S', t)):(NaN):xtic(strftime(int(i)%6?'%H:%M':'%m-%d',t)) t ""
$data嘿!我问有没有一个明智的方法可以做到这一点!:):)说真的,你的是一个伟大而有用的解决方案。我需要一段时间来理解这里发生的一切。非常感谢。附言:使用原始问题中的数据实际测试您的解决方案,您将获得额外的感谢积分。我希望有更多的人这样做!为您提供具有代表性的数据集还可获得额外的积分:)嘿!我问有没有一个明智的方法可以做到这一点!:):)说真的,你的是一个伟大而有用的解决方案。我需要一段时间来理解这里发生的一切。非常感谢。附言:使用原始问题中的数据实际测试您的解决方案,您将获得额外的感谢积分。我希望有更多的人这样做!提供代表性数据集也可获得额外积分:)