Fixing 'matplotlib non-GUI backend' error in Jupyter notebook

If you're encountering the 'matplotlib non-GUI backend' error in Jupyter notebook, it means that the default backend for matplotlib is not compatible with Jupyter's non-GUI environment. However, you can easily fix this error by changing the backend to one that is compatible with Jupyter.

├Źndice
  1. Step 1: Check your current backend
  2. Step 2: Install a GUI backend
  3. Step 3: Restart the kernel

Step 1: Check your current backend

Before changing the backend, you should check what your current backend is. To do this, run the following code in a Jupyter notebook cell:

import matplotlib.pyplot as plt
print(plt.get_backend())

This will print the name of your current backend. If the backend is 'agg', 'svg', or 'pdf', then you need to change it to a GUI backend.

Step 2: Install a GUI backend

If you don't have a GUI backend installed, you'll need to install one. The most common GUI backend is 'TkAgg', which can be installed by running the following command in your terminal:

pip install tk

Once you've installed 'TkAgg', you can set it as your backend by adding the following code to your Jupyter notebook:

import matplotlib
matplotlib.use('TkAgg')

Step 3: Restart the kernel

After changing the backend, you'll need to restart the kernel for the changes to take effect. To do this, go to the 'Kernel' menu in Jupyter notebook and select 'Restart Kernel'.

Once you've completed these steps, you should no longer encounter the 'matplotlib non-GUI backend' error in Jupyter notebook.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information