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]
},
Plot({
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?
)
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…
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
"\\node[..."
and get the same result. Just that because of all the LaTeX code, raw"..." is easier.
We introduced some new syntax that makes it easier to write \node commands in LaTeX with computed information. (Otherwise, if you are manually specifying it, @jbrea’s solution is simpler). Slightly tweaking the example to demo this,
using PGFPlotsX
x_in = range(-100/π, stop = 100.0/π, length = 1000);
coords = (-15.0, 0.3)
@pgf p = Axis({ xmin = x_in[1], xmax = x_in[end], ymax = 1.2 },
Plot({ color = "blue" },
Table(x_in, @. abs(sin(x_in)/x_in))),
VLine({ dashed, red }, coords[1]),
HLine({ dashed, blue }, coords[2]),
[raw"\node",
{ anchor = "south west", pin = "0:this is the red line" },
" at ", Coordinate(coords[1], 1.1), "{};"])