• Matplotlib warning [error?] message

    From Leif Svalgaard@lsvalgaard@gmail.com to comp.lang.python on Sun Feb 18 10:40:38 2024
    From Newsgroup: comp.lang.python

    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
    leif@leif.org
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Zahraa Fadhil@zahraazirjawi@gmail.com to comp.lang.python on Sun Feb 18 12:17:19 2024
    From Newsgroup: comp.lang.python

    On Sunday, February 18, 2024 at 10:48:29 PM UTC+3, Leif Svalgaard wrote:
    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

    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()
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Leif Svalgaard@lsvalgaard@gmail.com to comp.lang.python on Mon Feb 19 09:39:16 2024
    From Newsgroup: comp.lang.python

    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
    leif@leif.org
    --- Synchronet 3.20a-Linux NewsLink 1.114