Skip to content

Cannot display latex correctly in make_subplots #4340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zhimin-z opened this issue Aug 27, 2023 · 1 comment
Open

Cannot display latex correctly in make_subplots #4340

zhimin-z opened this issue Aug 27, 2023 · 1 comment
Assignees
Labels
bug something broken P3 backlog

Comments

@zhimin-z
Copy link

zhimin-z commented Aug 27, 2023

I am using make_subplots and insert latex math expression but it displays incorrectly.
Here is my sample code:

import plotly.graph_objs as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=2)

trace1 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6])
trace2 = go.Scatter(x=[20, 30, 40], y=[50, 60, 70])

fig.add_trace(trace1, row=1, col=1)
fig.add_trace(trace2, row=1, col=2)

fig.update_layout(
    xaxis=dict(title='$x^2$'),
    xaxis2=dict(title='$\\sqrt{x}$')
)

fig.show()

Here is my output:
image

As you can see, it does not display correctly.

My setup:
OS: Ubuntu 20.04
Python: 3.10.9
Plotly: 5.16.1

@zhimin-z
Copy link
Author

zhimin-z commented Aug 27, 2023

I tried with another function in Plotly, I confirm latex display is dead in Jupyter notebook:

import plotly.graph_objects as go

# Create data
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 5, 3]

fig = go.Figure()

fig.add_trace(go.Scatter(x=x, y=y))

# Configure MathJax options
fig.update_layout(
    meta={
        "mathjax": "svg", # this did not seem to fix the problem
    },
    font_family='Times New Roman', # this is important for journal publications
    title=r'$\text{Render Bug Only Happens in the PDF!}$',
    xaxis_title=r'$\Omega=v+\boldsymbol{w} \text{ this all looks bold}$',
    yaxis_title='This is not bold as it\'s a regular string.',
    showlegend=False,
)

fig.show()
fig.write_image('plot.pdf')

Here is the output:
image

@nicolaskruchten @chriddyp @jonmmease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants