What to do when matplotlib gets angry on CentOS saying "I'm using Agg so I can't issue a figure"

phenomenon

Run this code on CentOS.

test.py


import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()

Then I get this error.

$ python3 test.py
test.py:3: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()

Countermeasures

Install tkinter.

sudo yum install python3-tkinter

Then, after that, the graph is displayed properly.

$ python3 test.py

image.png

Cause

By default, Python 3 on CentOS only includes non-GUI Agg. If you include tkinter, the GUI-backend TkAgg will be enabled and you will be able to use it.

By the way, depending on the article

import matplotlib
matplotlib.use('TkAgg')

It is written that it is necessary to explicitly specify TkAgg like, but in my environment (CentOS Linux release 7.8.2003), just insert python3-tkinter (X is valid) It seems that it will be used automatically.

Recommended Posts

What to do when matplotlib gets angry on CentOS saying "I'm using Agg so I can't issue a figure"
What to do when Japanese is not displayed on matplotlib
I built an environment from centos installation to php source expansion on linux, but what to do when a browser error occurs
What to do when you get "I can't see the site !!!!"
What to do if you get angry if you don't have libxml / xmlversion.h when installing lxml on CentOS
What I stumbled upon when using CodeIgniter on a Linux server
Notes on what to do when matplotlib scatter () / scatter3d () does not work
Suddenly I needed to work on a project using Python and Pyramid, so a note of how I'm studying
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if SciPy installation fails on CentOS
What to do when gdal_merge creates a huge file
What I was addicted to when using Python tornado
What to do when you can't bind CaboCha to Python
I'm always impatient when ordering a cafe, so I made a React app to solve it.
A note of what I learned when I thought about using pyenv or virtualenv on Windows
What to do when you get an error saying "Name resolution temporarily failed" on linux
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
What to do when a Remove Error occurs when updating conda
I stumbled when I tried to install Basemap, so a memorandum
What to do if `pip install matplotlib` fails on Mac
What to do if you can't use WiFi on Linux
A note when I can't open Jupyter Notebook on Windows
I was a little addicted to installing Python3.3 + mod_wsgi3.4 on Sakura VPS (CentOS), so a retrospective memo
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow