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

Regular non-Solara plots not showing in Jupyter Notebooks after Solara has been used #703

Closed
EwoutH opened this issue Jul 3, 2024 · 6 comments

Comments

@EwoutH
Copy link
Contributor

EwoutH commented Jul 3, 2024

For some reason, regular matplotlib and seaborn plots don't show anymore after a Solara page has been initiated. In the code below you can see the first seaborn plot showing well, but the second not showing.

In PyCharm, the first plot is also shown fine, but instead of just not showing the second plot anymore, but gives an error:

ipykernel_29332\2165788151.py:2: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
  plt.show()

Here's a notebook to reproduce: solara_bug_plotting.zip
And here's the same notebook in Google Colab.

First plot shows fine:
image

After a Solara component, the second errors or doesn't show anymore:

image

@EwoutH
Copy link
Contributor Author

EwoutH commented Jul 3, 2024

A workaround is adding %matplotlib inline before the second plot.

I still think this is weird behavior.

@maartenbreddels
Copy link
Contributor

Does this also happen after a simple solara import?
After this happens, can you check if solara.server.patch is in sys.modules?

@EwoutH
Copy link
Contributor Author

EwoutH commented Jul 3, 2024

Thanks for getting back.

Taking some minimal examples, it looks like everything works fine: solara_minimal_test.zip

Which means probably something is wrong with our implementation. Can you spot anything obvious?

@maartenbreddels
Copy link
Contributor

https://github.com/projectmesa/mesa/blob/74e2df6fdfc2d5172f84eb96469b277b35bfd795/mesa/visualization/jupyter_viz.py#L39 seems suspicious.
Maybe you have added that because that was needed before #540 to run under solara server.
Now things should just run.

@EwoutH
Copy link
Contributor Author

EwoutH commented Jul 3, 2024

Thanks! Let me check it out.

@EwoutH
Copy link
Contributor Author

EwoutH commented Jul 3, 2024

I think that help, I at least don't need the %matplotlib inline anymore (which is quite logical in hindsight).

The JetBrains (PyCharm) implementation is also still not rock solid:
image

But it now works most of the time, with reloading a cell or two!

Thanks for the quick responses, really appreciated!

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

No branches or pull requests

2 participants