Search code examples
plotgnuplot

Place an icon on line at first instance of a value?


I have a gnuplot script as below:

#!/usr/bin/gnuplot -persist

set terminal x11
line = "./test.csv"
plot line using 1 with lines linecolor 1 linewidth 3 title "Line"

And my test.csv file:

0.92
0.74
0.65
0.59
0.48
0.46
0.24
0.11
0.09
0.05
0.03
0.01

This produces a plot like so:

enter image description here

I want to see the point where the line has gone below 0.1. Is there a way to mark this position either by some icon on the line or perhaps a vertical dotted line. Something like below:

enter image description here

For this, where x=9, it is the first time y<0.1, so it's been marked to illustrate this example.

Is there something in gnuplot that can do this? I know with line styles I can represent my line as symbols like a star or +; I'd love to have one of those at a specific point.


Solution

  • A one round version with pointsize variable:

    $line <<EOD
    0.92
    0.74
    0.65
    0.59
    0.48
    0.46
    0.24
    0.11
    0.09
    0.05
    0.03
    0.01
    EOD
    
    hit=0; plot $line using 0:1:(hit=hit+($1<0.1), hit==1?3:0) with lp ps var pt 7 lw 3 title "Line"
    

    To get the bar, one can use a second errorbar plot.

    hit=0; plot $line using 1 w l lw 3 title "Line",\
               "" using 0:(hit=hit+($1<0.1), $1/(hit==1)):(0):(1) w e  lc 1 pt 7 ps 3 title ""