Lurch
Lurch

Reputation: 875

Marking zero values with a red line in gnuplot

I have a .csv datafile that outputs values from 0 to 500 i.e

25.2
2.82
2.05
2.13
2.42
2.17
2.00
0
0
0
0
3.33
3.41
3.26
3.30
0
27.8

and plot it using

plot 'out.csv' using 1 with lines

From that file I would like any 0 values to be marked on the graph with a single red line

enter image description here

Upvotes: 0

Views: 108

Answers (1)

theozh
theozh

Reputation: 25843

Depending on what exactly you are looking for, the following would be my suggestion from what I understood from your question. Plot the data again with impulses and filtered with the ternary operator (check help ternary).

Script:

### plot with ternary operator
reset session

# create some random test data
set samples 300
set table $Data
    plot '+' u (rand(0)<0.97 ? (rand(0)**20)*500+1 : 0) w table
unset table

set key out

plot $Data u 1 w l lc 1 ti "data", \
        '' u ($1==0 ? 500 : NaN) w impulses lc "red" ti "0 value"
### end of script

Result:

enter image description here

Upvotes: 1

Related Questions