Skip to content

Need help? Join our Discord Community!

Tutorials
Matplotlib
Overcoming the 'matplotlib is currently using agg' Issue

Matplotlib's Common Hurdle: 'matplotlib is currently using agg'

'matplotlib is currently using agg' is an issue that many Python enthusiasts face while working with Matplotlib for data visualization. This error message suggests that Matplotlib is utilizing a non-graphical user interface (GUI) backend, hindering the display of figures or plots. It's time to dig deep into this issue and uncover the ways to navigate around it.

Understanding GUI and Non-GUI backends

To tackle the issue, it's important first to understand the concept of GUI and non-GUI backends.

GUI Backend: The Visualization Powerhouse

GUI, short for graphical user interface, is the interactive medium between the user and computing devices. It leverages visual elements like windows, icons, and menus, thereby enabling users to interact seamlessly with their devices. In Python, Tkinter is the most frequently employed method for GUI development.

Non-GUI Backend: The Text-based Interaction Mode

Conversely, a non-GUI backend is a machine-based interaction mode that operates sans graphics, relying solely on text-based communication. The warning message 'matplotlib is currently using agg' is an indication that Matplotlib is using a non-GUI backend.

Addressing 'matplotlib is currently using agg' Issue

Given below are solutions to resolve the 'matplotlib is currently using agg' error.

Solution #1: Install Tkinter, a GUI Backend

Installing a GUI-backend like Tkinter can remedy the situation. Here's how to install it across different environments:

Linux

To install the GUI backend in Linux, use the following command:

sudo apt-get install python3-tk

Jupyter Notebook

To introduce the GUI backend to a Jupyter notebook, run:

pip install tk

Post installation, import the Tkinter library using the following syntax:

from tkinter import *

Anaconda Distribution

For Anaconda users, the Tkinter installation command is:

conda install tk

Once installed, the Tkinter library can be imported with:

import tkinter

Solution #2: Install PyQt5, Another GUI Backend

An alternative GUI backend to consider is PyQt5, a Python binding for the Qt libraries, often used in GUI application development. Here's how to install PyQt5:

Jupyter Notebook

Use the following command to install PyQt5 in Jupyter Notebook:

pip install pyqt5

Linux

For Ubuntu Linux or Debian Linux users, the PyQt5 installation command is:

sudo apt-get install python3-pyqt5

CentOS 7

CentOS 7 users can install PyQt5 by running:

yum install qt5-qtbase-devel

Redhat based System

RPM-based system users, including Redhat, can use:

yum install PyQt5

Anaconda Distribution

For those using the Anaconda Prompt, the command is:

conda install pyqt

Closing Thoughts

Though 'matplotlib is currently using agg' can initially seem intimidating, it's a hurdle that can be smoothly navigated with proper understanding and the right commands. By equipping Matplotlib with a robust GUI backend like Tkinter or PyQt5, the data visualization process can continue unabated, fueling Python's capabilities for insightful and interactive plotting.

Need to Quickly Create Charts/Data Visualizations? You can give VizGPT (opens in a new tab) a try, where you can use ChatGPT prompts to create any type of chart with No Code!

How to Create Charts with VizGPT (opens in a new tab)

VizGPT: Create Charts with the Power of ChatGPT (opens in a new tab)