6

I have data in file and they have date/time point and value. The line in data is written only when value change. For example:

10:01  12.00
10:12   8.00
10:14   9.00

I would like to plot a graph which will not draw line straight from one point to other, drawing declining line, but keep horizontal line until point 10:12 and then jump to value 8.00 and then keep horizontal line in value 8.00 until end then jumping to 9.00

I was searching around, but the challenge is that I have no idea what is proper name of such a graph. I hope you can help me to draw it in gnuplot. Thank you in advance.

richo
  • 63
  • 3
  • 3
    I agree, it's difficult to search for it if you don't know how it is called. Check http://gnuplot.sourceforge.net/demo_5.2/steps.html, the first example shows the difference between `steps`, `fsteps`, and `histeps`. – theozh May 08 '19 at 05:41

1 Answers1

6

Actually, there is even another step style fillsteps. I found a little example in my own fund. It also illustrates how the styles behave when there is an empty line in the data. The lines are slightly shifted to better see the differences.

Code:

### plot with steps
reset session

$Data <<EOD
1 -1
2 -1
3  1
4 -1

6 -1
7 -1

8  0.5

9 -1
11 -1
13  1
14  1
EOD

set colorsequence classic
set ytics 1
set mxtics 2
set yrange[-1.2:1.9]
set grid xtics, mxtics, ytics
set key center top
  plot \
    $Data u 1:2 w fillsteps lw 0 fs transparent solid 0.1 fc "black" t "fillsteps",\
    '' u ($1-0.05):($2*1.02) w steps lt 1 lw 2 t "steps",\
    '' u ($1+0.05):($2*0.97) w fsteps lt 2 lw 2 t "fsteps",\
    '' u 1:2 w histeps lt 3 lw 2 t "histeps",\
    '' u 1:2 w p lt 7 lw 2 lc "black" t " data points"
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • Thank you for great answer, answer in such a way that I also learned lot of useful things for the future. The answer for my question is "using steps". I would vote for the answer but I have less then 15 reputation and I am not allowed. Thanks again theozh. – richo May 10 '19 at 09:19
  • 1
    You're welcome! You can vote later when you will have >15 ;-). Actually, I slighly changed the data in order to illustrate that a point separated by empty lines will not be plotted with `step`, `fsteps` and `fillsteps`, but with `histeps`. – theozh May 10 '19 at 10:32