1

How can I annotate outside of a plot.

Here is an example:

using Plots, LaTeXStrings

gr()
x = LinRange(0.0,2π, 100)
y= sin.(x)
plt = plot(x, y, 
            label=["aPlot"], 
            legend= :outertopright, 
            legend_column=1
          )
scatter!(plt, x[1:3:100], y[1:3:100], markersize = 1, legend_column=2)

str = L"\begin{bmatrix}
        1&  2\\
        3&  4\\
        \end{bmatrix}"

annotate!(10, 1, str)

How can I set the str to be below the legend outside of the plotting area?

nop nop
  • 83
  • 6

1 Answers1

0

I don't know if I entirely follow the question- rendering outside the plot is possible with the code you already have. The issue is with the LaTeX renderer in Plots.jl. Replacing

str = L"\begin{bmatrix}
        1&  2\\
        3&  4\\
        \end{bmatrix}"

with str = L"y = \sin(x)", gives us this:

plot after adjusting the position of str using the x and y parameters of the annotate! call.

Reading the documentation for LaTeXStrings.jl, it states:

FAQ: Not a LaTeX renderer

LaTeXStrings does not do any rendering — its sole purpose is to make it easier to enter LaTeX-rendered strings without typing a lot of backslash escapes, as well as providing a type to tell display backends to use LaTeX rendering if possible.

*Other packages like plotting software, Jupyter notebooks, Pluto, etcetera, are responsible for the LaTeX rendering (if any). For example, they might use MathJax, MathTeXEngine.jl, or other renderers. LaTeXStrings only provides the LaTeX text to these backend, and has no influence on what LaTeX features (if any) are supported. [emphasis mine]

Running equivalent code using GLMakie, I get an error that \begin isn't supported. I can't find the renderer used by Plots.jl in their source code, but it seems clear that whichever one they use, it doesn't support the LaTeX that you're trying within str.

Mark
  • 7,785
  • 2
  • 14
  • 34
  • There is likely a way of getting around the bad renderer used by Plots (on my computer?). If anyone knows, please comment – Mark Jul 18 '23 at 08:33