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 saw in several places that one had to change the configuration of matplotlib using the following:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
I did this, but then got an error message because it cannot find a module:
ModuleNotFoundError: No module named 'tkinter'
Then, I tried to install "tkinter" using pip install tkinter
(inside the virtual environment), but it does not find it:
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
I should also mention that I am running all this on Pycharm Community Edition IDE using a virtual environment, and that my operating system is Linux/Ubuntu 18.04.
I would like to know how I can solve this problem in order to be able to display the graph.
To Solve UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure Error Here Error is mentioning that You must have installed GUI backend So that Just Install the GUI backend tk Using this command: sudo apt-get install python3-tk Second solution is You just need to install ...
The last, Agg, is a non-interactive backend that can only write to files. It is used on Linux, if Matplotlib cannot connect to either an X display or a Wayland display.
Matplotlib is not thread-safe: in fact, there are known race conditions that affect certain artists. Hence, if you work with threads, it is your responsibility to set up the proper locks to serialize access to Matplotlib artists. You may be able to work on separate figures from separate threads.
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.
matplotlib
supported GUI backendsTkAgg
Qt5Agg
, GTKAgg
, Qt4Agg
, etc
pip install pyqt5
will fix the issue alsoNOTE:
matplotlib
made the pypi software deps not depend on any GUI backend because some people need matplotlib
without any GUI backend.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With