Search code examples
gnuplot

Text label over point gnuplot


I would like to insert a text label (Latex style) close to a point as in the image shown in the following. Unfortunately I could only find examples that let to plot, for example, the coordinates of the point as label but nothing related to the text labels

enter image description here


Solution

  • Not sure I understand the question, but as a starting point I point out that all labels in gnuplot are anchored to some position, and have an optional property "point" that draws a symbol at that anchor position. Whether that is left, right, or center with respect to the text depends on the text justification, futher modifiable using "offset".

    Example:

    f(x) = x + 2*sin(x)
    set xrange [0:10]
    set border 3
    set tics nomirror
    # gnuplot enhanced text version
    set label 1 "V_p" at 3,f(3) point pointtype 7 offset 0,1
    # LaTeX version
    set label 1 "$V_p$" at 3,f(3) point pointtype 7 offset 0,1
    plot f(x)
    

    caveat: the position of the label is evaluated at the time of the set label command, so if you change the definition of f(x) later you would have to re-execute the set label. enter image description here

    2nd caveat: If plot is to be generated using one of gnuplot's LaTeX terminal (pslatex, tikz, cairolatex, ...) then all the text used, including the label, must conform to LaTeX syntax rather that gnuplot's own text markup. Generally this means enclosing simple expressions in $...$ and using LaTeX macros for odd characters rather than UTF-8. In order for the leading backslash of the macros to be passed through, use single quotes rather than double quotes:

      gnuplot non-latex terminal:  set label "a→∞"
      gnuplot latex terminal:      set label '$a\to\infty$'