Plotting labeled intervals in matplotlib/gnuplot

后端 未结 3 1494
死守一世寂寞
死守一世寂寞 2020-12-01 06:40

I have a data sample which looks like this:

a 10:15:22 10:15:30 OK
b 10:15:23 10:15:28 OK
c 10:16:00 10:17:10 FAILED
b 10:16:30 10:16:50 OK

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 07:01

    gnuplot with vector solution

    Minimized from: http://gnuplot.sourceforge.net/demo_5.2/gantt.html

    main.gnuplot

    #!/usr/bin/env gnuplot
    
    $DATA << EOD
    1 1 5
    1 11 13
    2 3 10
    3 4 8
    4 7 13
    5 6 15
    EOD
    
    set terminal png size 512,512
    set output "main.png"
    set xrange [-1:]
    set yrange [0:]
    unset key
    set border 3
    set xtics nomirror
    set ytics nomirror
    set style arrow 1 nohead linewidth 3
    plot $DATA using 2 : 1 : ($3-$2) : (0.0) with vector as 1, \
         $DATA using 2 : 1 : 1 with labels right offset -2
    

    GitHub upstream.

    Output:

    You can remove the labels by removing the second plot command line, I added them because they are useful in many applications to more easily identify the intervals.

    The Gantt example I linked to shows how to handle date formats instead of integers.

    Tested in gnuplot 5.2 patchlevel 2, Ubuntu 18.04.

提交回复
热议问题