PGFPlotsX: annotate outside plot area

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


using Plots
annotate!(0.5,0.5,text("inside plot"))
annotate!(0,0.5,text("outside plot",:center))

Results in outside plot being cut:


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

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) {};")


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


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


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.


1 Like

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

plot_font = "Computer Modern"
        linewidth=2, framestyle=:box, label=nothing, grid=false)

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

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:

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.


These look great.

1 Like

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:

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)}}")