gnuplothighlight

Gnuplot: highlight specific values


In Gnuplot, can I highlight specific values on a linear graph? By highlight", I mean draw the lines from the axis values to a specific point on the graph and print that spot with a dot. I have a few such interesting values. I can "draw" all this manually with "set arrow" etc, but I wonder if there's a built-in mechanism.

enter image description here


Solution

  • EDIT2: As @Ethan answered, there will be a built-in solution since version 6.0. Until then, there is a hand-made solution, if you have a function f(x) [left image]:

    # gnuplot 5.4.4
    reset; set grid;
    
    xmin=0
    ymin=0
    
    set xrange [xmin:]
    set yrange [ymin:]
    
    highlight(x, y, xmin, ymin) \
            = sprintf("set arrow from %f,%f to %f,%f nohead lw 2 lc -1; \
                       set arrow from %f,%f to %f,%f nohead lw 2 lc -1; \
                       set label at %f,%f point pt 7 lc -1 ps 2; ", xmin, y, x, y, x, ymin, x, y, x, y)
            
    f(x)=0.5*x+0.2
            
    eval highlight(4,2.2,xmin,ymin)
    eval highlight(6,f(6),xmin,ymin)
    
    plot f(x) notitle
    

    Example Example of extended answer

    EDIT: as the OP asked for a solution which uses data points from a file instead of a function, there is a possible solution [right image]:

    # gnuplot 5.4.4
    reset; set colors classic; set grid
    
    datafile='007_d.dat'
    
    xmin=0
    ymin=0
    
    set xrange [xmin:]
    set yrange [ymin:]
    
    highlight(x, y, xmin, ymin) \
            = sprintf("set arrow from %f,%f to %f,%f nohead lw 2 lc -1; \
                       set arrow from %f,%f to %f,%f nohead lw 2 lc -1; \
                       set label at %f,%f point pt 7 lc -1 ps 2; ", xmin, y, x, y, x, ymin, x, y, x, y)
    
    byx(x) \
            = sprintf("plot datafile u ($1 == %f ?$1:1/0):2; \
                      eval highlight(GPVAL_DATA_X_MIN,GPVAL_DATA_Y_MIN,xmin,ymin)", x)
    
    byy(y) \
            = sprintf("plot datafile u ($2==2.7?$1:1/0):2; \
                      eval highlight(GPVAL_DATA_X_MIN,GPVAL_DATA_Y_MIN,xmin,ymin)", y)
                      
    eval highlight(4,2.2,xmin,ymin)
    eval byx(6)
    eval byy(2.7)
    
    plot datafile w lp ps 2 notitle
    

    NOTE: you can use datafile as an extra parameter for byx() / byy() ofcourse; also you can play with xmin amd ymin as your particular needs.

    ATTENTION: the code assumes, that you have unique x-y data pairs.