LaTeX code for titles, labels,... with Plots.jl



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.


You need using LatexStrings


This worked, thanks. Any idea how to set the numbers on the x/y axis to LaTeX?


try xticks?


Works like a charm, for completeness, my code is now:

using Plots
using LaTeXStrings

p = plot(0:2,0:2, xlab = L"x^2", xticks = ([0,1,2],[L"0", L"1", L"2"]))

and my problem has been solved completely.


Which backends does this work with?


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.


Either plotly() and plotlyjs() backend doesn’t work for me
Maybe it has something to do with OS language?


I am on OS X - I get the same occasionally, but most times it works with plotlyjs(). It is bit strange.


@mkborregaard The correct capitalization of the package name is LaTeXStrings.


Indeed it is, thanks for the dilligence.


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.