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

Plotting animations do not seem to be compatible with Jupyter Notebook 7 #261

Closed
ljchang opened this issue Mar 11, 2024 · 2 comments
Closed

Comments

@ljchang
Copy link
Contributor

ljchang commented Mar 11, 2024

There was a major update to Jupyter Notebook/Lab from Version 6 to Version 7 this past year.

The hypertools helper functions that deal with backends when plotting animations do not seem to be compatible with the new version of jupyter notebook.

Screenshot 2024-03-11 at 7 17 29 PM

Everything works when I switch to using the old version (i.e., nbclassic).

Just wanted to bring this to your attention. Thanks!

paxtonfitzpatrick added a commit to paxtonfitzpatrick/hypertools that referenced this issue Mar 15, 2024
@paxtonfitzpatrick
Copy link
Member

paxtonfitzpatrick commented Mar 19, 2024

hey @ljchang, thanks for the report, and apologies for the delay. Turns out there were actually 2 separate bugs here:

  1. The TypeError in your screenshot was thrown by one of the callback functions Hypertools registers with IPython's EventManger for managing the Matplotlib backend around interactive/animated plots. Basically, we defer resetting the plotting backend until just before the next cell you run is executed so that animations don't stop when switching back to inline static plotting. IPython used to be pretty lenient about these callbacks' signatures but it looks like that changed in v8.17 (Attempt to remove backcall. ipython/ipython#14216).
  2. The reason the plot itself wasn't displaying is related to the update from Notebook v6 ➡️ v7. The notebook v7 frontend now uses the same JavaScript library as JupyterLab, which doesn't expose the global IPython and Jupyter JS objects that Matplotlib's default backend for interactive inline plots in "classic" notebooks (nbAgg) relied on. Looks like most everything (now including Hypertools) has transitioned to using ipympl for inline animations, but the various GUI-based interactive backends should still work too (Qt[4|5]Agg, GTK[3|4]Agg, TkAgg, WebAgg, WXAgg, MacOSX, etc.)

I've implemented fixes for both issues in paxtonfitzpatrick/hypertools@fa28a79. Once I merge those in (hopefully tonight), I'll take a look at #262 (thanks for that PR as well!).

@paxtonfitzpatrick
Copy link
Member

@ljchang this should now be fixed on master if you'd like to try it out!

pip install git+https://github.com/ContextLab/hypertools.git

Animated & interactive plots should now automatically work in both "classic" notebooks and Notebook v7+, as well as in JupyterLab.

One quick thing to note is that if you run your Jupyter notebook/lab server from a different environment than your IPython kernel, you'll also need to pip install ipympl into the notebook server's environment, then shutdown and re-launch the server. This will provide the JS components that the notebook/lab frontend needs to display interactive plots.

I'm gonna close this for now, but if you run into any more issues please feel free to re-open! Thanks again!

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