Plots.jl : positioning and scaling of "annotate!"

I would like to put on the lower right corner of my plots a notification text string, typically citing the the “data source : date of production”

Although I can put text using

annotate!(xpos, ypos, "my text", :color)

it is presently missing some needed options for which I didn’t manage to find a solution either going through the Plots.jl documentation or searching discourse.

What I’m looking for is:

  • how to change the font used (presently by default it’s way too big)
  • how to make it right aligned.

N.B. all this is possible by using PyPlot directly, but I want to move away from that to a more Julian-like and consistent way of doing.

I’d appreciate some help.
All the best,
Rob

1 Like

annotate!(xpos, ypos, text("mytext", :red, :right, 3))
The text constructor is “magic” so the order of the various arguments isn’t important.

5 Likes

Thanks Mike,

  • with the gr() backend that does the trick! THANKS.

  • however when using the pgfsplots() backend (which is the one I usually employ), one cannot annotate below the x-axis, nor change the font-size

Can I bother you for how to change the font to “Courier”, “Sans” for instance (again I do not manage to extract this from the docs, nor ? or methods(text) get me any furher)?

Best,
Rob.

It should all be here http://docs.juliaplots.org/latest/examples/pgfplots/#annotations
The example actually uses courier.

One thing to consider if you’re using pgfplots because you’re embedding in LaTeX. Consider savefig("myfigure.tex"), the resulting figure should take fonts and stuff from the latex document.

1 Like

Here’s a more recent version of the link that is not actually dead https://docs.juliaplots.org/latest/generated/pgfplotsx/#pgfplotsx-ref20 :slight_smile:

1 Like

Your link is already dead again… current version seems to be here: Using LaTeX code · PGFPlotsX.jl

Is it possible to place an annotation at position (x,y) on a plot as described above but to also have the value of a variable displayed? I have in mind something like “Position =” z. Here the value of the variable z would be placed after the text.

You can achieve this by using $ in a string to specify the value of your variables.
For example:
annotate!(x, y, Plots.text("$x, $y", :red, :right, 10))

updated link to Plots annotate! documentation example: Annotations · Plots

1 Like