绘制日期和时间间隔以及持续时间 [英] Plot date and time interval and duration

查看:91
本文介绍了绘制日期和时间间隔以及持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要绘制为条形图的日期和时间开始和结束的列表.X轴应从00:00-23:59开始,Y轴应显示日期

我尝试在 gnuplot 中进行绘图,但是我的技能还不够好.

数据采用以下格式:

<代码>日期开始停止06.03.2019 09:45 11:1706.03.2019 14:40 15:2007.03.2019 08:35 10:1507.03.2019 14:05 14:4508.03.2019 09:15 10:2008.03.2019 13:55 14:4509.03.2019 08:55 09:5009.03.2019 13:15 14:3610.03.2019 09:05 10:00

我想得到一个类似的图,但是在Y轴上的日期和同一图中的所有条形图.像这样:

I have a list of date+time start and stop that I would like to plot as bars. The X-axis should go from 00:00-23:59 with date on the Y-axis

I tried plotting in gnuplot, but my skills are not good enough.

The data is in the following format:

Date Start Stop 06.03.2019 09:45 11:17 06.03.2019 14:40 15:20 07.03.2019 08:35 10:15 07.03.2019 14:05 14:45 08.03.2019 09:15 10:20 08.03.2019 13:55 14:45 09.03.2019 08:55 09:50 09.03.2019 13:15 14:36 10.03.2019 09:05 10:00

I would like to get a plot similar like this, but dates on the Y-axis and all bars in the same plot. Like this: https://i.stack.imgur.com/A98t2.png.

Any help is greatly appreciated.

解决方案

The following might be a starting point. The bars are plotted with with boxxyerror. In this code, days without entries will not appear as label on the y-axis. Intervals which cross midnight need to be handled differently.

Code:

### plot start stop times
reset session

$Data <<EOD
06.03.2019  09:45   11:17
06.03.2019  14:40   15:20
07.03.2019  08:35   10:15
07.03.2019  14:05   14:45
08.03.2019  09:15   10:20
08.03.2019  13:55   14:45
09.03.2019  08:55   09:50
09.03.2019  13:15   14:36
10.03.2019  09:05   10:00
12.03.2019  01:01   12:59
13.03.2019  00:00   23:59
EOD

$SpecialEvents <<EOD
08.03.2019  8:00
11.03.2019  4:00
13.03.2019  12:00
EOD

StartDay = "06.03.2019"
DaysAfterStartDay(day) = int((strptime("%d.%m.%Y",day)-strptime("%d.%m.%Y",StartDay))/86400)

set xdata time
set timefmt "%H:%M"
set format x "%H:%M"

plot $Data u (timecolumn(2)):(y=DaysAfterStartDay(strcol(1))): \
    (timecolumn(2)):(timecolumn(3)):(y-0.2):(y+0.2):ytic(1) w boxxyerror \
    fs solid 1.0 lc rgb "blue" notitle, \
    $SpecialEvents u (timecolumn(2)):(DaysAfterStartDay(strcol(1))):ytic(1) \
    with points pt 7 ps 2 lc rgb "red" notitle
### end of code

Result:

这篇关于绘制日期和时间间隔以及持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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