"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm
I am trying to plot a simple graph using pyplot, e.g.:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()
but the figure does not appear and I get the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
I found and tried some advice to re-configure the "backend" mentioned in that warning, like so:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
but this gives me an error message:
ModuleNotFoundError: No module named 'tkinter'
I assumed that I had to install this module separately, but pip install tkinter does not work:
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
How can I make Matplotlib display the graph?
See also: Why does tkinter (or turtle) seem to be missing or broken? Shouldn't it be part of the standard library? . This question is not a duplicate, because the answers discuss other backends besides the Tkinter one.
Also see _tkinter.TclError: no display name and no $DISPLAY environment variable for issues with attempts to use Matplotlib remotely.Solution 1: is to install the GUI backend tk I found a solution to my problem (thanks to the help of ImportanceOfBeingErnest). All I had to do was to install tkinter through the Linux bash terminal using the following command: sudo apt-get install python3-tk instead of installing it with pip or directly in the virtual environment in Pycharm. Solution 2: install any of the matplotlib supported GUI backends solution 1 works fine because you get a GUI backend... in this case the TkAgg however you can also fix the issue by installing any of the matplolib GUI backends like Qt5Agg, GTKAgg, Qt4Agg, etc for example pip install pyqt5 will fix the issue also NOTE: usually this error appears when you pip install matplotlib and you are trying to display a plot in a GUI window and you do not have a python module for GUI display. The authors of matplotlib made the pypi software deps not depend on any GUI backend because some people need matplotlib without any GUI backend.
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/7f396d288fd0d88488628d3332e0d8cdd0a5752f2b2dc722bbfe888076f426a8