问题
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.
回答1:
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:
回答2:
There is a Gantt chart demo in the on-line collection.
#
# 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
来源:https://stackoverflow.com/questions/55926835/plot-date-and-time-interval-and-duration