Possible bug in wxPython or matplotlib.pyplot?

"[email protected]" <[email protected]> Sun, 26 Jun 2022 10:12:45 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
------=_Part_1660_1817861790.1656263565133
Content-Type: multipart/alternative; 
	boundary="----=_Part_1661_2109224042.1656263565133"

------=_Part_1661_2109224042.1656263565133
Content-Type: text/plain; charset="UTF-8"

Dear all

I ran into an issue with wxPython and matplotlib.pyplot. Please take a look 
at the attached code example. It runs fine as it is on my Linux machine. 
However, if I uncomment the plt.subplots_adjust(...) line, it hangs at exit.

Am I doing something wrong, or is this a bug? If it is a bug, is it in 
wxPython or in matplotlib?

wxPython version 4.0.7
matplotlib version 3.5.2
Debian SID

------------------------------------
from numpy import arange, sin, pi
import matplotlib
matplotlib.use('WXAgg')

import matplotlib.pyplot as plt

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as 
FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

class CanvasPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.figure = Figure()
        self.axes1 = self.figure.add_subplot(2,1,1)
        self.axes2 = self.figure.add_subplot(2,1,2)
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()
        
        ### plt.subplots_adjust(hspace=0.4) # <-- This causes trouble!
        
    def draw(self):
        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)
        self.axes1.plot(t, s)
        self.axes2.plot(t, -s)


if __name__ == "__main__":
    app = wx.App()
    fr = wx.Frame(None, title='test')
    panel = CanvasPanel(fr)
    panel.draw()
    fr.Show()
    app.MainLoop()
------------------------------------

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/c2cb8664-bd10-4875-b5c3-cf2d5cda5dbfn%40googlegroups.com.

------=_Part_1661_2109224042.1656263565133
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>Dear all</div><div><br></div><div>I ran into an issue with wxPython an=
d matplotlib.pyplot. Please take a look at the attached code example. It ru=
ns fine as it is on my Linux machine. However, if I uncomment the plt.subpl=
ots_adjust(...) line, it hangs at exit.</div><div><br></div><div>Am I doing=
 something wrong, or is this a bug? If it is a bug, is it in wxPython or in=
 matplotlib?</div><div><br></div><div>wxPython version 4.0.7</div><div>matp=
lotlib version 3.5.2</div><div>Debian SID<br></div><div><br></div><div>----=
--------------------------------</div><div>from numpy import arange, sin, p=
i<br>import matplotlib<br>matplotlib.use('WXAgg')<br><br>import matplotlib.=
pyplot as plt<br><br>from matplotlib.backends.backend_wxagg import FigureCa=
nvasWxAgg as FigureCanvas<br>from matplotlib.backends.backend_wx import Nav=
igationToolbar2Wx<br>from matplotlib.figure import Figure<br><br>import wx<=
br><br>class CanvasPanel(wx.Panel):<br>&nbsp; &nbsp; def __init__(self, par=
ent):<br>&nbsp; &nbsp; &nbsp; &nbsp; wx.Panel.__init__(self, parent)<br>&nb=
sp; &nbsp; &nbsp; &nbsp; self.figure =3D Figure()<br>&nbsp; &nbsp; &nbsp; &=
nbsp; self.axes1 =3D self.figure.add_subplot(2,1,1)<br>&nbsp; &nbsp; &nbsp;=
 &nbsp; self.axes2 =3D self.figure.add_subplot(2,1,2)<br>&nbsp; &nbsp; &nbs=
p; &nbsp; self.canvas =3D FigureCanvas(self, -1, self.figure)<br>&nbsp; &nb=
sp; &nbsp; &nbsp; self.sizer =3D wx.BoxSizer(wx.VERTICAL)<br>&nbsp; &nbsp; =
&nbsp; &nbsp; self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)<br=
>&nbsp; &nbsp; &nbsp; &nbsp; self.SetSizer(self.sizer)<br>&nbsp; &nbsp; &nb=
sp; &nbsp; self.Fit()<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbs=
p; &nbsp; ### plt.subplots_adjust(hspace=3D0.4) # &lt;-- This causes troubl=
e!<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; def draw(self):<br>&nbs=
p; &nbsp; &nbsp; &nbsp; t =3D arange(0.0, 3.0, 0.01)<br>&nbsp; &nbsp; &nbsp=
; &nbsp; s =3D sin(2 * pi * t)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.axes1.pl=
ot(t, s)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.axes2.plot(t, -s)<br><br><br>i=
f __name__ =3D=3D "__main__":<br>&nbsp; &nbsp; app =3D wx.App()<br>&nbsp; &=
nbsp; fr =3D wx.Frame(None, title=3D'test')<br>&nbsp; &nbsp; panel =3D Canv=
asPanel(fr)<br>&nbsp; &nbsp; panel.draw()<br>&nbsp; &nbsp; fr.Show()<br>&nb=
sp; &nbsp; app.MainLoop()</div><div>------------------------------------</d=
iv>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxpy=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/c2cb8664-bd10-4875-b5c3-cf2d5cda5dbfn%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/wxpython-users/c2cb8664-bd10-4875-b5c3-cf2d5cda5dbfn%40googlegroups.=
com</a>.<br />

------=_Part_1661_2109224042.1656263565133--

------=_Part_1660_1817861790.1656263565133--