绘制日期和时间间隔和持续时间

问题描述 投票:0回答:2

我有一个日期+时间开始和停止的列表,我想绘制为条形。 X轴应在00:00-23:59之间,日期在Y轴上

我尝试在gnuplot密谋,但我的技能还不够好。

数据采用以下格式:

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

我想得到一个类似这样的情节,但是在Y轴上的日期和同一情节中的所有条形。像这样:https://i.stack.imgur.com/A98t2.png

任何帮助是极大的赞赏。

date plot time gnuplot intervals
2个回答
0
投票

以下可能是一个起点。用with boxxyerror绘制条形图。在此代码中,没有条目的天数不会在y轴上显示为标签。跨越午夜的间隔需要以不同方式处理。

码:

### 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

结果:

enter image description here


0
投票

在线收藏中有一个甘特图演示。

#
# Very simple Gantt Chart
# Demonstrate using timecolumn(N,format) to plot time data from 
# multiple columns
#
$DATA << EOD
#Task start      end
A     2012-11-01 2012-12-31
B     2013-01-01 2013-03-14
C     2013-03-15 2014-04-30
D     2013-05-01 2013-06-30
E     2013-07-01 2013-08-31
F1    2013-09-01 2013-10-31
F2    2013-09-01 2014-01-17
F3    2013-09-01 2014-01-30
F4    2013-09-01 2014-03-31
G1    2013-11-01 2013-11-27
G2    2013-11-01 2014-01-17
L     2013-11-28 2013-12-19
M     2013-11-28 2014-01-17
N     2013-12-04 2014-03-02
O     2013-12-20 2014-01-17
P     2013-12-20 2014-02-16
Q     2014-01-05 2014-01-13
R     2014-01-18 2014-01-30
S     2014-01-31 2014-03-31
T     2014-03-01 2014-04-28
EOD

set xdata time
timeformat = "%Y-%m-%d"
set format x "%b\n'%y"

set yrange [-1:]
OneMonth = strptime("%m","2")
set xtics OneMonth nomirror
set xtics scale 2, 0.5
set mxtics 4
set ytics nomirror
set grid x y
unset key
set title "{/=15 Simple Gantt Chart}\n\n{/:Bold Task start and end times in columns 2 and 3}"
set border 3

T(N) = timecolumn(N,timeformat)

set style arrow 1 filled size screen 0.02, 15 fixed lt 3 lw 1.5

plot $DATA using (T(2)) : ($0) : (T(3)-T(2)) : (0.0) : yticlabel(1) with vector as 1, \
     $DATA using (T(2)) : ($0) : 1 with labels right offset -2

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.