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

**URL:** <https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967>\
**Category:** General Usage\
**Tags:** question, package, plotting\
**Created:** [February 7, 2017, 8:57pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967 "2017-02-07T20:57:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Holy\_Monk](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@Holy\_Monk](https://discourse.julialang.org/u/Holy_Monk)\
**Post date:** [February 7, 2017, 8:57pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/1 "2017-02-07T20:57:10Z")

</div>

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:

```julia
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](https://github.com/sisl/PGFPlots.jl), but this is still being developped for Plots.jl.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 7, 2017, 9:07pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/2 "2017-02-07T21:07:57Z")

</div>

You need `using LatexStrings`

---

<div class="post-metadata">

**Author:** ![Holy\_Monk](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@Holy\_Monk](https://discourse.julialang.org/u/Holy_Monk)\
**Post date:** [February 7, 2017, 9:10pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/3 "2017-02-07T21:10:38Z")

</div>

> [@mkborregaard](#):
>
> LatexStrings

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

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 7, 2017, 9:12pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/4 "2017-02-07T21:12:33Z")

</div>

try `xticks`?

---

<div class="post-metadata">

**Author:** ![Holy\_Monk](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@Holy\_Monk](https://discourse.julialang.org/u/Holy_Monk)\
**Post date:** [February 7, 2017, 9:19pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/5 "2017-02-07T21:19:47Z")

</div>

> [@mkborregaard](#):
>
> xticks

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

```julia
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!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 8, 2017, 3:10am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/6 "2017-02-08T03:10:29Z")

</div>

Which backends does this work with?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 8, 2017, 6:07am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/7 "2017-02-08T06:07:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [February 8, 2017, 12:54pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/8 "2017-02-08T12:54:56Z")

</div>

> [@Holy\_Monk](#):
>
> ```julia
> using Plots
> using LaTeXStrings
> 
> p = plot(0:2,0:2, xlab = L"x^2", xticks = ([0,1,2],[L"0", L"1", L"2"]))
> 
> ```

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

 ![](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff199b942e6b0fe09b65b63cee560ae08a344d77.png)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 8, 2017, 1:01pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/9 "2017-02-08T13:01:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tparker](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tparker](https://discourse.julialang.org/u/tparker)\
**Post date:** [June 6, 2017, 2:00am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/10 "2017-06-06T02:00:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [June 6, 2017, 5:49am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/11 "2017-06-06T05:49:37Z")

</div>

Indeed it is, thanks for the dilligence.

---

<div class="post-metadata">

**Author:** ![tparker](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tparker](https://discourse.julialang.org/u/tparker)\
**Post date:** [June 9, 2017, 9:09pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/12 "2017-06-09T21:09:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [August 2, 2018, 7:24am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/14 "2018-08-02T07:24:41Z")

</div>

> [@tparker](#):
>
> `LaTeXStrings`

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…

EDIT: Sorry… got it: `label="\${\\overline{fitted}} \\thinspace prices\$")`

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 6, 2018, 12:23pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/15 "2018-08-06T12:23:43Z")

</div>

Sorry for the reviving this thread again but I’m struggling to get this right:

```julia
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.

---

<div class="post-metadata">

**Author:** ![mcarpe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcarpe/32/2719_2.png) [@mcarpe](https://discourse.julialang.org/u/mcarpe)\
**Post date:** [August 6, 2018, 6:50pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/16 "2018-08-06T18:50:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 6, 2018, 7:46pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/17 "2018-08-06T19:46:45Z")

</div>

…agree wrt. PyPlot, but on my computer (Win10), PyPlot doesn’t work in Juno – for some reason.

---

<div class="post-metadata">

**Author:** ![Rob\_van\_Weelderen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rob_van_weelderen/32/7621_2.png) [@Rob\_van\_Weelderen](https://discourse.julialang.org/u/Rob_van_Weelderen)\
**Post date:** [August 7, 2018, 9:43am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/18 "2018-08-07T09:43:45Z")

</div>

Hi Nils,

I found that for the **title** and **gr() backend** one has to use the `latexstring()` function directly instead of `L"some latex code"`.

Below an example code

```julia
using Plots, LaTeXStrings

gr()

date = "07-08-2018"
titlestring = latexstring("\\mathrm{My\\, \\alpha\\, including\\, a\\, variable\\, date:\\,}", date)

plot(sin, (0:0.01:5*pi), dpi=300,
     title = titlestring,
     xlabel = L"\mathrm{My\, x-label\, (mJ/cm^{3})}",
     ylabel = L"\mathrm{\alpha (m/s)}")

```

Rob.

---

<div class="post-metadata">

**Author:** ![davidzentlermunro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidzentlermunro/32/5967_2.png) [@davidzentlermunro](https://discourse.julialang.org/u/davidzentlermunro)\
**Post date:** [December 20, 2018, 7:35pm UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/19 "2018-12-20T19:35:19Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [December 21, 2018, 1:26am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/20 "2018-12-21T01:26:40Z")

</div>

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\$”.

---

<div class="post-metadata">

**Author:** ![Carol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carol/32/8140_2.png) [@Carol](https://discourse.julialang.org/u/Carol)\
**Post date:** [September 25, 2019, 4:40am UTC](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967/21 "2019-09-25T04:40:51Z")

</div>

Hi, I still have this problem. I just want to set my y label as “Unit is 10^3”, where the 10^3 should be latex symbol.

I’m using Juno with latest version of Julia, and none of above suggestions works.

[Next page](https://discourse.julialang.org/t/latex-code-for-titles-labels-with-plots-jl/1967.md?page=2)
