# PGFPlotsX: annotate outside plot area

**URL:** <https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357>\
**Category:** Visualization\
**Tags:** question, pgfplotsx\
**Created:** [April 1, 2021, 12:38pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357 "2021-04-01T12:38:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 1, 2021, 12:38pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/1 "2021-04-01T12:38:37Z")

</div>

How can I put annotations outside the plotting area of a plot in PGFPlotsX?

Example:

```julia
using Plots
pgfplotsx(grid=:false)
scatter(rand(5),rand(5),xlim=[0,1],ylim=[0,1])
annotate!(0.5,0.5,text("inside plot"))
annotate!(0,0.5,text("outside plot",:center))

```

Results in `outside plot` being cut:

![image](https://global.discourse-cdn.com/julialang/original/3X/7/3/73af2f6fd9b5851f0832de814d822785511bf1ac.png)

edit: specifically, I want to add “A”, “B”, “C”, etc, to a grid layout of plots.

---

<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:** [April 2, 2021, 3:08pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/2 "2021-04-02T15:08:56Z")

</div>

```julia
using PGFPlotsX
@pgf Axis({ xmin = 0, xmax = 1, ymin = 0, ymax = 1, clip = false},
          Plot({ only_marks }, Table(rand(5), rand(5))),
          raw"\node[label={inside},circle,fill,inner sep=2pt,red] at (axis cs:0.5,0.5) {};",
          raw"\node[label={outside},circle,fill,inner sep=2pt,red] at (axis cs:0,0.5) {};")

```

 ![x](https://global.discourse-cdn.com/julialang/original/3X/9/7/970cbedfd49b28f756dcf636b22783d188b113ab.png)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 4, 2021, 5:48pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/3 "2021-04-04T17:48:54Z")

</div>

Thanks @Tamas_Papp. Unfortunately that diverges too much from my use of it (I am just using PGFPlotsX as the backend for Plots).

For now I will stick with

```julia
plot!(title="A",title_position=:left,subplot=1)
plot!(title="B",title_position=:left,subplot=1)

```

to add my labels, although I don’t really like where they end up:

![image](https://global.discourse-cdn.com/julialang/original/3X/5/3/534ff914813a7680e46d5908cabc311846a6369a.png)

With the GR backend the annotations that are set to the last subplot are over all other elements, and thus we can put these labels A, B, C,… as annotations in the last plot, but wherever in canvas one wants. With PGFPlotsX they only appear within the plot region of the corresponding subplot.

I will keep searching for a better solution (other than opening the file in inkscape and moving the labels by hand). I want to stick with PGFPlotsX for the consistency of the fonts, of course.

Leandro.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 25, 2021, 6:45pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/4 "2021-04-25T18:45:38Z")

</div>

Just for the register, I finally stuck with GR. Using this one sets the fonts of almost everything to Computer Modern:

```julia
plot_font = "Computer Modern"
default(fontfamily=plot_font,
        linewidth=2, framestyle=:box, label=nothing, grid=false)

```

And for the annotations, the fonts have to be manually set with:

```julia
annotate!(-32, 41,subplot=4,text("A",plot_font,14,:left,:bottom))

```

The annotations, associated to the last subplot (`4` here), appear above all other elements of the figure.

That with LaTexStrings provides a nice plot with homogeneous fonts:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/3/938eab33aef8e3fbb2cb7ee2589d2ab8a1c67e7a.png)

Ah, and these options work for the latest versions of Plots (1.12) and GR (0.57.4). For previous versions my experience was less smooth.

---

<div class="post-metadata">

**Author:** ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)\
**Post date:** [April 26, 2021, 9:21pm UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/5 "2021-04-26T21:21:37Z")

</div>

These look great.

---

<div class="post-metadata">

**Author:** ![transarcus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/transarcus/32/11186_2.png) [@transarcus](https://discourse.julialang.org/u/transarcus)\
**Post date:** [April 9, 2022, 10:47am UTC](https://discourse.julialang.org/t/pgfplotsx-annotate-outside-plot-area/58357/6 "2022-04-09T10:47:52Z")

</div>

I had the same problem as you Imiq with the same desire to use pgfplotsx as a backend of plots. I didn’t want to change to GR because of the nice latex integration and tikz export ability of pgfplotsx. I ended up going with this slightly nasty solution of editing the output file to shift the title:

```julia
savefig(all,"Sensing.tikz")
test=readlines("Sensing.tikz")
outfile = "Sensing.tikz"
open(outfile, "w") do f
    for i in 1:length(test)
        test[i]=replace(test[i], raw"title style={at={{(0,1)}}" => raw"title style={at={{(-0.2,1)}}")
        println(f,test[i])
    end
end

```
