Skip to content

Math in Plotly Figure Labels are not rendering using Quarto provided Mathjax #12060

@EaLeaR

Description

@EaLeaR

I'm writing a report using Jupyter notebook in VSCode and I'm enable to use math expressions in figure labels while writing math in markdown too!
The output I'm trying to generate is an HTML file.

Here is my observations:

  • I need to add a MathJax library to be able to show math properly in plotly figure labels.
  • This works well (labels show correctly and figure maintain interactivity) as long as I don't add math in markdown.
  • Once I add math in markdown the labels disappear and figure loses interactivity.

Here is a MRE reproducing the issue:

---
format:
  html:
    execute: true
jupyter: python3
---

```{python}
import plotly.express as px
from IPython.display import display, HTML

display(HTML(
    '<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>'
))

fig = px.line(x=[0, 1, 2, 3, 4],
              y=[1, 2, 4, 8, 16],
              )
fig.update_layout(yaxis_title = '$2^x$',
                  xaxis_title = '$x$',
                  )
fig.show()
```

Math in Markdown:

$$x$$

Metadata

Metadata

Assignees

No one assigned

    Labels

    mathany issue related to math support in specific formatsplotly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions