Python is one of the most popular programming languages to ever come out, mostly because it’s rather simple for beginners to understand but still powerful enough to write strong code often involving AI, ML and computer vision projects.
How to fix the error?
The solution for this is actually quite simple. As you might know already, Jupyter Labs supports interactive matplotlib graphs using the jupyter-matplotlib extension. You can install the extension using Conda or Pip by using the commands given below.
If you’re using Python’s in-built package manager Pip, here’s how you can install the jupyter-matplotlib extension for both Jupyter Labs and Jupyter Labs 2.
pip install ipympl # If using JupyterLab 2 pip install nodejs jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter labextension install jupyter-matplotlib
Similar to Pip, Conda is also an open-source package manager that acts as an alternate source for many popular libraries. In case Pip doesn’t work for you, or you just prefer using Conda, you can use the following commands based on your situation to install jupyter-matplotlib.
conda install -c conda-forge ipympl # If using JupyterLab 2 conda install nodejs jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter lab build # Later, if updating a previous Lab install: conda install ipympl jupyter lab build
Once installed, you can use it by adding this line before plotting the graph.
Alternatively, as a workaround you can also configure matplotlib to use inline instead of interactive. It’s not as powerful, but will sidestep the error for you. To use inline, simply add this line before plotting the graph.
Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars. You can reach out to Yadullah at [email protected], or follow him on Instagram or Twitter.