Latex typesetting in Plots with plotly backend?

I am using Plots.jl and plotly for making plots, but I would like to have my legend, title and labels typed in latex. Using LaTeXStrings and the syntax L"…" works for gr and pyplot backends, but not for plotly. Does anyone have any idea how to write latex strings with plotly?


This doesn’t answer your question, but if you want fully customizable LaTeX, consider

1 Like

Currently it doesn’t work in the Juno IDE, but it does work in IJulia, if you copy the correct fonts to the mathjax directory:

  • Download
  • copy the jax -folder to C:\Users\<username>\.julia\conda\3\Lib\site-packages\notebook\static\components\MathJax or wherever this is on your system. Note that there might be more MathJax folders, (e.g. C:\Users\<username>\.julia\conda\3\pkgs\notebook-6.0.3-py36_0\Lib\site-packages\notebook\static\components\MathJax, but only one is the true source for the server.

The background seems to be that Mathjax changed the default font to TeX, but the current distribution that comes with Jupyter only contains Stix-Web. I have posted this recently on stackoverflow.

using Plots, LaTeXStrings

Plots.plot(1:4, [[1,4,9,16], [0.5, 2, 4.5, 8]], 
    labels = [L"\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}" L"\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}"],
    xlabel = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}",
    ylabel = L"d, r \text{ (solar radius)}"


The following lines make it available in Juno. Make sure, Conda is installed and the files are copied as described above.

using Plots, LaTeXStrings


import Plots.plotly_html_head
import Conda.ROOTENV

function mathjax()
    mathjaxdir = joinpath(ROOTENV, "Lib\\site-packages\\notebook\\static\\components\\MathJax")
    mathjaxfile =  joinpath(mathjaxdir, "MathJax.js?config=TeX-AMS-MML_HTMLorMML-full")
    return """<script type="text/javascript" src="$mathjaxfile"></script>"""

function Plots.plotly_html_head(plt::Plots.Plot)
    local_file = ("file://" * Plots.plotly_local_file_path)
    plotly = Plots.use_local_dependencies[] ? Plots.local_file : Plots.plotly_remote_file_path
    if Plots.isijulia() && !Plots.ijulia_initialized[]
        # using requirejs seems to be key to load a js depency in IJulia!
        display("text/html", """
        <script type="text/javascript">
        requirejs([$(repr(plotly))], function(p) {
        window.Plotly = p
        ijulia_initialized[] = true
    return """$(mathjax())
    <script src=$(repr(plotly))></script>"""