# PGFPlotsX howto annotate?

**URL:** <https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246>\
**Category:** Visualization\
**Tags:** plotting, pgfplotsx\
**Created:** [July 11, 2019, 10:27am UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246 "2019-07-11T10:27:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_van\_Weelderen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rob_van_weelderen/32/7621_2.png) [@Rob\_van\_Weelderen](https://discourse.julialang.org/u/Rob_van_Weelderen)\
**Post date:** [July 11, 2019, 10:27am UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/1 "2019-07-11T10:27:47Z")

</div>

Hello,

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:

```julia
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?
          )

```

Thanks in advance for your help,  
Rob.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 11, 2019, 1:36pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/2 "2019-07-11T13:36:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rob\_van\_Weelderen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rob_van_weelderen/32/7621_2.png) [@Rob\_van\_Weelderen](https://discourse.julialang.org/u/Rob_van_Weelderen)\
**Post date:** [July 11, 2019, 1:55pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/3 "2019-07-11T13:55:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [July 11, 2019, 2:05pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/4 "2019-07-11T14:05:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rob\_van\_Weelderen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rob_van_weelderen/32/7621_2.png) [@Rob\_van\_Weelderen](https://discourse.julialang.org/u/Rob_van_Weelderen)\
**Post date:** [July 11, 2019, 2:15pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/5 "2019-07-11T14:15:58Z")

</div>

> [@jbrea](#):
>
> “\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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 11, 2019, 2:29pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/6 "2019-07-11T14:29:48Z")

</div>

> [@Rob\_van\_Weelderen](#):
>
> 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](https://docs.julialang.org/en/v1/manual/strings/#man-raw-string-literals-1) which allows you to input strings without a lot of escape `\`s. It does not have anything to do with PGFPlotsX, you could do

```julia
"\\node[..."

```

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

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 11, 2019, 5:02pm UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/7 "2019-07-11T17:02:48Z")

</div>

There is currently no good julia interface in PGFPlotsX.jl for the `node` stuff ([https://github.com/KristofferC/PGFPlotsX.jl/issues/36](https://github.com/KristofferC/PGFPlotsX.jl/issues/36)) so, for now, one needs to use raw strings.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 23, 2019, 8:39am UTC](https://discourse.julialang.org/t/pgfplotsx-howto-annotate/26246/8 "2019-07-23T08:39:24Z")

</div>

We introduced some [new syntax](https://kristofferc.github.io/PGFPlotsX.jl/dev/examples/latex/) 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,

```julia
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), "{};"])

```

produces

 ![x](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff1cd7856beda2ca2c38f40b61cad66881965efc.png)
