-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 working in jupyter notebook v7. #4336
Comments
Ok, I installed the |
No, sorry it also doesn't work, the previous code snippet just literally shows from plotly.graph_objects import Figure
Figure().update_layout(title=r"$Title$") |
Hi, I faced the same issue, any update? |
No, I still need some solution for this 😅 |
Yeah, still there... @newville |
@zhimin-z Yes, the problem still exists. Is there any understanding of the cause of the problem? Has anyone investigated what is going on in the code? I'm afraid this is a bit outside of my area of expertise. |
I have no idea...anyone who is in charge of latex functionality in this repo? |
I'm tagging @alexcjohnson since he seems to be the last to have committed something to jupyterlab-plotly other than version changes :) It looks like this is an easy fix that just needs an update to use the latest MathJax version, or somehow forcing jupyterlab to use an oldest one, I don't know if that's possible. |
@pfebrer @alexcjohnson Thanks for looking into this. Is there anything the rest of us can do to help further troubleshoot or fix this issue? I'll admit that I do not have a deep understanding of how plotply.py and plotly.js interact or which version of mathjax |
I don't know, everything I know is that jupyterlab uses MathJax I don't even know how to modify |
@pfebrer Thanks, sorry to be dense, but what precisely would one have to do to make it work? Could that be folded into the plotly-py code? The issue is kind of 3 months old, and it seems that there has been no explanation or acknowledgment of this issue. |
I don't know, if I knew I would have submitted a PR already :) I already tried to fix it and I couldn't even set up a dev environment. I'm not a plotly developer so I don't have more time to spend on it unfortunately. They already marked it as a bug, so I guess they'll address it whenever they have time. The bug is very annoying and I guess plenty of people will find it since everyone uses jupyter notebooks, so eventually they will have to fix it if they don't want people to move to other packages because of this very small detail. |
My impression for this was that |
@pfebrer @alexcjohnson it looks like maybe this is related to #3661, #3696, and #3706, first identified 18 months ago and related to plotly using MathJax 2 when other code (say, Jupyter) has already loaded MathJax 3. FWIW, the last release of MathJax2 was 3 years ago. MathJax 3 has been actively developed, and MathJax 4 is now in beta. |
As @pfebrer pointed out, Plotly.js has been able to use MathJax v3 or v2 since plotly/plotly.js#6073 which was released in v2.10 (March 2022), so the problem is something about how we're detecting or invoking MathJax in certain environments. I have to admit my own attempts a few months ago to get multiple versions of Jupyter and Jupyterlab installed side-by-side so I could test and fix these issues left me with a borked environment that wouldn't run anything correctly, and I haven't tried to go back to it since then. So if someone else wants to give this a shot we'd welcome a PR - otherwise we'll get back to it at some point but I can't say when. @newville thanks for the note about MathJax 4, we'll give it a look! We'll certainly want to get it working in Plotly.js and Dash, regardless of the issues we've had in the various Jupyter environments. |
@alexcjohnson Thanks for the response. For me, running a standalone plot script, as in https://plotly.com/python/LaTeX/ from a plain Python shell works fine (Python 3.10.12 or 3.11.5 on MacOS) -- it opens a browser in Chrome and the plot correctly renders the LaTeX. Running that same script in a Jupyter Notebook fails to render the LaTeX. To reproduce, one should be able to install Miniforge (https://github.com/conda-forge/miniforge), activate that environment, and then install with
I might be willing to help, but I am having difficulty even navigating where to start here (not very fluent with the Jupyter code or Plotly). I cannot really even figure out where the
is coming from. |
If you open the browser console (F12) you'll see some more information. But the JavaScript files are minified so it's really an impossible mission to debug from there. That's why I tried to set up a dev environment, but I failed. @alexcjohnson maybe if you can point us to somewhere where it is explained how to set up the dev environment for the whole stack (plotly.py, jupyterlab-plotly, plotlyjs), we could try to help. Otherwise, at least in my case, it feels too difficult to try to contribute because I have to figure out everything myself and I don't know if I'm doing things right. |
@alexcjohnson @pfebrer Just in case it wasn't obvious (or in case it helps with debugging), downgrading to jupyter notebook < 7 does avoid this problem:
|
@alexcjohnson @pfebrer any thoughts on whether progress is going to be possible on this? Help (or an attempt to help, at least) was offered, but the very low response rate here is less than encouraging. I hope all is well. |
@alexcjohnson @pfebrer any updates on this? Perhaps a pull request on the documentation (https://github.com/plotly/plotly.py/blob/master/doc/python/LaTeX.md) to change that to state that latex formatting of strings is no longer supported in Jupyter would be in order? The current statement there is misleading at best. |
I have no idea how to fix it and I'm not part of the plotly team, so I don't see how I can help, sorry :( I would like to see this fixed as well, but there's nothing I can do. |
@pfebrer Thanks - I am in the same position. It seems like the developers are either ignoring this or won't be able to fix it. I think that perhaps the best option is to admit that this is not working, and put in a PR to change to documentation to say that latex strings do not work with Jupyter Notebook 7. |
I hope this gets moved up the priority list because it's kind of a dealbreaker for using plotly in scientific publications. Just had to fall back to matplotlib because I was not able to properly name my axes on jupyterlab 4.2.0. |
Currently migrating my report from plotly/plotly.js#5374 to here. import plotly.graph_objects as go
f=go.Figure()
f.update_yaxes(title=dict(text="$log_{10}(D)$", font_size=16))
f.show() ![]() |
@archmoj I think the better solution will be to fix up that default renderer instead of changing to iframe. |
Ah another quick solution here: try |
@marthacryan Thanks for the suggestion. When I do that, then I do not see any text labels at all (for the example at the start of this discussion). Can you give an example script that works for you? |
@newville Oh interesting. This is what I'm seeing for that example in both JupyterLab and Jupyter Notebook (v7): |
@marthacryan Thanks. ![]() |
@marthacryan iframe mode works, thanks! I don't mind the folders much, although it would be better if I could choose the name to something like .iframes. However, I remember that there were other issues that made plotly latex rendering subpar compared to matplotlib. @newville I think you forgot a rawstring marker (R'$\alpha...') but I noticed that even adding it, mixing normal text and latex in a string results in the normal text being ignored. But I get some latex rendered, so there is something different between my environment and yours. I think it is because I installed not only the notebook, but jupyter lab, and specifically jupyterlab_mathjax2 ( but the test below was run in the notebook). import sys,notebook,plotly
print(sys.version,sys.platform)
for m in (plotly,notebook):
print(m.__name__,m.__version__)
import plotly.graph_objects as go
f=go.Figure()
f.update_layout(title=dict(text=R'$\alpha$ Title'))
# f.update_yaxes(title=dict(text="a label $log_{10}(D)$", font_size=16))
f.show() ![]() Reproducing:micromamba create -n plotly_latex_bug jupyterlab jupyter plotly jupyterlab_mathjax2
micromamba run -n plotly_latex_bug jupyter notebook
micromamba run -n plotly_latex_bug jupyter lab |
What is the version of Mathjax on window when using default renderer? |
@marthacryan @LunarLanding The previous screen grab I did was on macOS. On Windows, with the So, the problem is not tied to one system or platform. |
@gvwilson Do I read the P3 label you added as meaning "not pressing"? Can you verify that you understand that this problem is actually a show-stopper for using plotly with the latest version of jupyter and jupyterlab? The first paragraph of the readme advertising this project (https://github.com/plotly/plotly.py/blob/master/README.md) literally says:
but that for anyone wanting to, you know, plot scientific data, that
fails to render a plot. Please verify that this issue is actually considered "not pressing". |
Hi @newville - "not pressing" means that no-one on my team is actively working on it in the current cycle. If other issues take less time to resolve than expected, we'll bump its priority and find someone to tackle it. PRs from the community are always welcome, and we'll review them as quickly as we can. Thanks - @gvwilson |
@gvwilson Oh. "not pressing" being short-hand for "not being actively worked on" seems like an odd usage to me. As with many open-source projects, it is very hard to know from GitHub alone who is on "the team"? It seems like you view "your team" and "the community" are different things. That could be self-fulfilling ;) As it happens, this Issue was first raised almost exactly one year ago. It sure seems like the Plotly developers will not be able to solve this. I hope that is not so, as it is unfortunately cripples using Plotly with Jupyter for many people with scientific data. I wish you all the best, but it is not clear to me who your target audience is. There are other graphics libraries out there. |
How do you install plotly? There hasn't been a public release yet since the bug was fixed. |
@pfebrer Ah, my bad I thought this was in the latest release. But to answer your question, either |
Then I guess it's just a matter of waiting for the next release 👍 |
|
@moonlighthalfwindow Thanks for checking out the rc! This fix was intended to fix the Jupyter Notebook 7 interface and JupyterLab 4 interface. I wasn't aware of the vscode issues with Latex but I can reproduce them and it appears that they've been going on for a long time based on this issue: microsoft/vscode-jupyter#8131. There is a workaround in that issue that I'll copy over here that did fix the behavior for me in vscode:
I will work on adding an actual fix to address this but I hope it helps you in the meantime! |
@RafalSkolasinski Thanks for trying out the rc! Which version of JupyterLab are you using? |
Well, that's embarrassing... I tried again the minimal example from the above
and it worked fine... I did, however, encounter issue when trying to create
but that's probably subject for a new issue.... |
@RafalSkolasinski I'm so glad that it's working for you in JL! And the anywidget error is actually not a bug but the new behavior. You can just |
Oh... I really thought anywidget is any widget... Like press a key... Could the error message then somehow include word package to remove the confusion? :) |
I recently upgraded to jupyter notebook v7 and I noticed that some plotly plots that previously rendered flawlessly now fail to render. I get the following output:
After some exploration I found out that it comes from an error using MathJax in
jupyterlab-plotly
. It tries to accessMathJax.config.startup.output
, butMathJax.config.startup
isundefined
.It is very easy to reproduce this error:
pip install jupyter plotly
jupyter notebook
.The text was updated successfully, but these errors were encountered: