Search code examples
dateplottimegnuplotintervals

Plot date and time interval and duration


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.sstatic.net/A98t2.png.

Any help is greatly appreciated.


Solution

  • 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:

    enter image description here