I am using Plots.jl for making plots, but I would like to have my legend, title, labels,… in latex typesetting. With other libraries I know I can just use L"…", but when I run the following code:
using Plots
plot(0:2,0:2, xlab = L"x")
I get the following error:
LoadError: UndefVarError: @L_str not defined
Optimally I would also like the numbers on the x-and y-axis to be LaTeX, therefore I know I can use the package PGFPlots, but this is still being developped for Plots.jl.
I have it working on all that I have installed (gr, plotlyjs, pyplot)
EDIT: wait, it sometimes fails on plotlyjs, though it works most times. Peculiar.
Note: you don’t need the LaTeXStrings package in order to render LaTeX in Plots.jl - it just makes doing so more convenient. You can use LaTeX directly in Plots.jl by manually escaping all the $s, \s, etc.
Hello, how would you use LaTeX in Plots without the LaTeXStrings package ? label="${\bar{fitted}} prices$" or label=L"{\bar{fitted}} prices" would not work…
Sorry for the reviving this thread again but I’m struggling to get this right:
using Plots, LaTeXStrings
plot(rand(100))
title!("This is an alpha: α") # produces ? for alpha
title!("This is an alpha: \$\\alpha\$") # produces $ α$
title!(L"This is an alpha: α") # produces nothing
title!(L"This is an alpha: \alpha") # produces nothing
title!(L"This is an alpha: $\alpha$") # produces $ α$
I can’t seem to find a combination that plots the Latex symbol without also plotting the dollar signs - any help appreciated.
In my (small) experience, it depends on the backend. If you’re using the default for Plots.jl (GR.jl), LaTeX doesn’t work very well. It only works if you’re using a string that is all LaTeX, e.g.:
title!("\$\\alpha\$")
Otherwise you should currently use a different backend. For me, PyPlot.jl usually does its job with LaTeX.
I’m having this issue too, and I’m getting extra dollar signs in all other backends : not sure if this is a juno issue, a backend issue or a plots issue…
I think the PyPlot backend is the only one that currently supports only part of the string being LaTeX, e.g. things like “foo \$\\infty\$”. In GR you get text with dollar signs.
As a workaround you can do e.g. “\$\\mathrm{foo}\,\\infty\$”.