Hello!
I’m trying to use LaTeX or MathJax to display mathematical expressions in the labels
dictionary values within the px.line
function. However, despite using the r"$...$"
syntax and other attempts, the mathematical expressions are not rendered correctly on the plot.
Here’s an example of the code I am using:
import plotly.express as px
import plotly.graph_objects as go
# Example data
df = px.data.gapminder()
# Attempt to use LaTeX in labels
fig = px.line(
df,
x='year',
y='gdpPercap',
title="GDP Over Time",
labels={'year': r"$t$", 'gdpPercap': r"$GDP_{pc}$"}
)
fig.show()
I expected the mathematical expressions to appear on the X and Y axes, but instead, plain strings are displayed. I have tried various syntaxes, but it doesn’t work.
Could you please confirm whether LaTeX is supported in the labels
parameter? If so, what is the correct way to apply it? Or is there another way to include mathematical expressions in the plot?
Thank you in advance for your help!