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

question
package
plotting

#1

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.


#2

You need using LatexStrings


#3

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


#4

try xticks?


#5

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.
Thanks!


#6

Which backends does this work with?


#7

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.


#8

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


#9

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


#10

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


#11

Indeed it is, thanks for the dilligence.


#12

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.