PGFPlotsX howto annotate?


I’m moving to using PGFPlotsX, for it’s suitability for producing good publication ready plots, and got following the PGFPlotsX.jl and PGFPlots documentation most that I need functioning.

However I got stuck in figuring out how to annotate a plot with a text to illustrate a specific point. I’d appreciate a hint on how to do that in a simple way (and would be nice to get that on the PGFPlotsX.jl examples).

Follows a minimum working example, however with the annotation missing:

using PGFPlotsX

x_in = range(-100/π, stop = 100.0/π, length = 100);

@pgf p = Axis({ xmin = x_in[1]
              , xmax = x_in[end]
                color = "blue"
               Table( x_in, @. abs(sin(x_in)/x_in) )
          HLine({ dashed, blue }, 0.3),
          VLine({ dashed, red }, -15.0),
          #now I want to put a text somewhere, say "this is the red line", Howto?

Thanks in advance for your help,

Your best option is usually finding an existing example in pgfplots (ie LaTeX code), the translating it to the syntax of PGFPlotsX.

If you need help, just please link an example.

Dear Tamas,

  • That’s (looking into pgfplots (LaTeX)) what I did, and what didn’t help me.
  • No good LaTeX example caught my eye -> so I put a M(not)WA in the post.
  • I expected that annotating a plot would be a regularly occurring thing to do for the PGFPlotX users in Julia and so a hint on how to do so rather obvious. But apparently not…

–> I’ll keep searching.

raw"\node[anchor = south west] at (-10, .4) {this is the red line};"


Thanks Johanni,

that was a useful answer! I didn’t expect one would have to use the raw command for such a common use case.

Note that raw is just a string literal which allows you to input strings without a lot of escape \s. It does not have anything to do with PGFPlotsX, you could do


and get the same result. Just that because of all the LaTeX code, raw"..." is easier.

There is currently no good julia interface in PGFPlotsX.jl for the node stuff ( so, for now, one needs to use raw strings.