Skip to content
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

LaTeX not rendering in Plotly figures based on notebook in VScode #14954

Closed
moonlighthalfwindow opened this issue Dec 23, 2023 · 1 comment
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@moonlighthalfwindow
Copy link

Environment data

  • [ ]

  • VS Code version: 1.85.1

  • Jupyter Extension version (available under the Extensions sidebar): v2023.11.1003402403

  • Python Extension version (available under the Extensions sidebar): v2023.22.1

  • OS (Windows | Mac | Linux distro) and version: WIndows 11 23H2

  • Python and/or Anaconda version: 3.12.0

  • Plotly version: 5.18.0

Expected behaviour

According to the example in the official Plotly :https://plotly.com/python/LaTeX/, the result should look like this:

import plotly.express as px
fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 9, 16], title=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$')
fig.update_layout(
    xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
    yaxis_title=r'$d, r \text{ (solar radius)}$'
)
fig.show()

image

In fact when I ran the code in a py file, it did have the desired effect in Chrome.

Actual behaviour

But when I use notebook in VScode it renders as follows:
newplot

I found that even though he doesn't render properly, he still outputs normal images when I use the code fig.write_image("test.png"):
test

Based on the #8131 , I found that just adding a line of code at the beginning renders it properly:

import plotly.express as px
from IPython.display import display, HTML
display(HTML(
    '<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG"></script>'
)) 


fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 9, 16], title=r'$\alpha_{1c} = `352` \pm 11 \text{ km s}^{-1}$')
fig.update_layout(
    xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
    yaxis_title=r'$d, r \text{ (solar radius)}$'
)
fig.show()

image

On this basis, even if I change this line of code to a comment, he still works and renders the picture(even if clicking reboot kernel):
image

But if at this point I close the file and reopen it, he'll fail to render it correctly again:
image

Steps to reproduce:

Simply run this code in a VScode notebook.

Logs

12:16:18.302 [info] Handle Execution of Cells 0 for e:\<username>\Desktop\test\tets.ipynb
12:16:18.308 [info] Kernel acknowledged execution of cell 0 @ 1703304978307
12:16:18.461 [info] End cell 0 execution after 0.154s, completed @ 1703304978461, started @ 1703304978307
@moonlighthalfwindow moonlighthalfwindow added the bug Issue identified by VS Code Team member as probable bug label Dec 23, 2023
@DonJayamanne DonJayamanne assigned amunger and unassigned DonJayamanne Jan 1, 2024
@amunger
Copy link
Contributor

amunger commented Jan 3, 2024

duplicate of #8131

@amunger amunger closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants