Black Lives Matter. Please consider donating to Black Girls Code today.

# LaTeX in layout title does not work properly

import plotly as py
import plotly.graph_objs as go

py.offline.init_notebook_mode(connected=True)
layout = go.Layout(title="This is a test: $2$")
data = [go.Scatter(x=[1, 2, 3], y=[4, 5, 6])]
fig = go.Figure(data=data, layout=layout)
py.offline.iplot(fig)


As you can see the title is not rendered properly (only the math portion is displayed). Version is 3.7.1.

Hi @bx6YYXE6,

At present you place LaTeX expressions inside the standard HTML-style text string. You’ll need to make the entire title string a single LaTeX expression. For example…

layout = go.Layout(title=r"$\text{This is a test:} \sqrt{2^4}$")


Hope that helps!
-Jon

2 Likes

Thanks. I’ll accept that as a solution although this makes the figure a bit ugly imho since this typesetting of the text portion will create a aesthetical discrepancy between the title and the rest of the figure. But I guess it is the only way to get some math rendered there.

It’s also worth mentioning that you can get pretty far using only the HTML markup and HTML symbol codes. This will cover, for example, super/sub scripts and greek letters.

import plotly as py
import plotly.graph_objs as go

py.offline.init_notebook_mode(connected=True)
layout = go.Layout(title="This is a test: &#960;r<sup>2</sup>")
data = [go.Scatter(x=[1, 2, 3], y=[4, 5, 6])]
fig = go.Figure(data=data, layout=layout)
py.offline.iplot(fig)


-Jon

1 Like

@jmmease Are there any plans to add sometime in the future the LaTeX title feature to axis titles for 3d graphs?

It works great for the plot title, but the dollar signs seem to be ignored as special characters when using them as the values of “xaxis_title”, “yaxis_title”, “zaxis_title” in the “scene” dictionary of Layout.