3

Recently, I had to upgrade my Jupyter Notebook and Python. After upgrading I encounter an issue with using built-in magic functions such as %matplotlib notebook or %matplotlib inline. At this moment I tried to downgrade it and use the older jupyter version but it does not help.

Do we have any solutions for this?

My Jupyter version is 7.1.3 Pyhton - 3.11.7

Error while viewing a graph.

14
  • 1
    One I can help with right out of the gate. %matplotlib notebook isn't for current JupyterLab or Jupyter Notebook 7+. Jupyter Notebook 7+ uses a lot of the same tech as JupyterLab and so you want to look for things that work with that. In place of %matplotlib notebook with current JupyterLab or Jupyter Notebook 7+, you generally want to install and use ipympl. Note that you have to install it. Very important. Then %matplotlib ipympl will work. See documentation here where it says, ... Commented May 3, 2024 at 17:38
  • <continued> "To activate the ipympl backend all you need to do is include the %matplotlib ipympl magic in the notebook." Commented May 3, 2024 at 17:38
  • That covers the %matplotlib notebook; however, what are you seeing when you run %matplotlib inline? That should still work. Commented May 3, 2024 at 17:43
  • Warning: Cannot change to a different GUI toolkit: ipympl. Using qt instead. Got this error when tried to import ipympl. Commented May 3, 2024 at 17:43
  • 1
    It seems it works when I try to clean my browser Cache. After that, it worked. Thanks for the help. %matplotlib ipympl works fine after clearing out the browser cache. Commented May 3, 2024 at 17:47

1 Answer 1

4

In place of %matplotlib notebook, with current JupyterLab or Jupyter Notebook 7+, you generally want to install and use ipympl. Note that you have to first install ipympl in your environment. This is very important. Restart everything, too. Restarting the kernel only is insufficient. (OP says clearing cache of browser helped. I've seen refreshing the browser Jupyter page sometimes be enough; however, honestly restarting machine or at least Jupyter and the browser is advised.)
Then following successful installation and refresh, %matplotlib ipympl will work much like %matplotlib notebook did with the older tech. See documentation here where it says:

"To activate the ipympl backend all you need to do is include the %matplotlib ipympl magic in the notebook."

%matplotlib notebook isn't for current JupyterLab or Jupyter Notebook 7+. Jupyter Notebook 7+ uses a lot of the same tech as JupyterLab, and so you want to look for things that work with that.

Finally, if you prefer the older way with %matplotlib notebook, you can continue to use NbClassic at this time, see here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.