Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matplotlib warning [error?] message

75 views
Skip to first unread message

Leif Svalgaard

unread,
Feb 18, 2024, 2:48:29 PMFeb 18
to
The latest[?] version of Matplotlib cannot show a figure. I get the
annoying error message: "Matplotlib is currently using agg, which is a
non-GUI backend, so cannot show the figure"
I'm using Spyder python 3.11 on Windows 11.
What to do?

--
Leif Svalgaard
le...@leif.org

Zahraa Fadhil

unread,
Feb 18, 2024, 3:17:37 PMFeb 18
to
I have the same problem
try this
1) add this line first
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

2) delete this line from your cod.....matplotlib.use('Agg')

3) save the result into png file
plt.savefig('D:\data\mygraph.png')


another solution
https://www.w3schools.com/python/trypandas.asp?filename=demo_ml_dtree4

import sys
import matplotlib
matplotlib.use('Agg')
....
import matplotlib.pyplot as plt
....
#Two lines to make compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()

Leif Svalgaard

unread,
Feb 19, 2024, 1:20:39 PMFeb 19
to
now I get:
File e:\getmodpot.py:40
fig,ax = initPlot()

File E:\mystuff.py:272 in initPlot
fig,ax = plt.subplots(figsize=(xs,ys))

File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:1501 in subplots
fig = figure(**fig_kw)

File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in
wrapper
return func(*args, **kwargs)

File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:840 in figure
manager = new_figure_manager(

File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:384 in
new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)

File ~\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:3573 in
new_figure_manager

File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in
wrapper
return func(*args, **kwargs)

File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:2505 in __init__
"The Figure parameters 'layout' and 'constrained_layout' "

File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:213 in __init__
self.set(**kwargs)

File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:147 in <lambda>
cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)

File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:1227 in set
return self._internal_update(cbook.normalize_kwargs(kwargs, self))

File ~\anaconda3\Lib\site-packages\matplotlib\cbook\__init__.py:1771 in
normalize_kwargs
for canonical, alias_list in alias_mapping.items()

AttributeError: 'Figure' object has no attribute 'items'

--
Leif Svalgaard
le...@leif.org
0 new messages