9

I was trying to use %matplotlib widget to achieve interactivity in Jupiter Lab. But the output plot and widgets only showed up as texts. How to make the actual plot and widgets show up?

%matplotlib widget
import matplotlib.pyplot as plt
plt.figure()
x = [1,2,3]
y = [4,5,6]
plt.plot(x,y)

Output:

Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …
[1]:
[<matplotlib.lines.Line2D at 0x114777b38>]
alyishere
  • 93
  • 1
  • 4
  • I believe you're missing `plt.show()` – Yuca Aug 01 '19 at 21:32
  • 3
    No, it is not because of missing `plt.show()`. I have exactly the same problem, no figure, same text output! Ans also surprisingly since yesterday. I wonder if it is a problem with a new version of Jupyter Lab being released or something like that – NeStack Aug 03 '19 at 14:11
  • @alyishere Has my answer solved your problem? If not leave a comment and I will try to help, if yes please accept as a solution – NeStack Aug 04 '19 at 22:18

2 Answers2

3

I know question is old, but google brought me here when I had exactly the same issue, and I eventually figured it out.

In my case, I had neglected to install @jupyter-widgets/jupyterlab-manager. Adding this via the lab extensions tab, rebuilding and reloading resolved the issue for me.

mufassir
  • 406
  • 5
  • 16
Paidoo
  • 379
  • 3
  • 13
  • Thank you so much! This is exactly what I missed! – Jarvis Du Mar 16 '21 at 01:57
  • Glad it helped! :) If you update to JupyterLab 3.*, see my answer here. The process is much simpler! https://stackoverflow.com/a/66246240/10705616 – Paidoo Mar 16 '21 at 08:51
-2

I had exactly the same problem. Apparently, there is an issue with the Jupyter Lab version and packages, see here what other users with the same problem have written.

The things that enabled the visualization of the plots for me are:

1.) Make sure that you have Jupyter Lab version > 1.0 and ipywidgets > 7.5 installed, as adviced here. Just type in a jupyter lab cell !jupyter lab --version, !conda list ipywidgets and check for yourself.

2.) Open Jupyter Lab from the terminal with the command jupyter lab. I was using before a programme that was making for me a short cut, so I don't have to open the terminal, but it was opening an older version of Jupyter Lab

NeStack
  • 1,739
  • 1
  • 20
  • 40