Re: Possible bug in wxPython or matplotlib.pyplot?

Matt Newville <[email protected]> Sun, 26 Jun 2022 13:20:29 -0500
Newsgroups gmane.comp.python.wxpython
Message-ID <CA+7ESbosEj3X_QdBoKqMfgnmPNgO-NbOAZQDLJx2-2cSCCNYmw@mail.gmail.com>
--000000000000dfdfc005e25dddd9
Content-Type: text/plain; charset="UTF-8"

I suggest removing
    import matplotlib.pyplot as plt
completely and not using the `pyplot` interface at all.

You already have an instance of a Figure, so you should be able to replace
    plt.subplots_adjust(hspace=0.4)

with
   self.figure.subplots_adjust(hspace=0.4)



On Sun, Jun 26, 2022 at 12:12 PM [email protected] <[email protected]>
wrote:

> 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
> <https://groups.google.com/d/msgid/wxpython-users/c2cb8664-bd10-4875-b5c3-cf2d5cda5dbfn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


--Matt

-- 
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/CA%2B7ESbosEj3X_QdBoKqMfgnmPNgO-NbOAZQDLJx2-2cSCCNYmw%40mail.gmail.com.

--000000000000dfdfc005e25dddd9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,sans-serif"><br></div></div><div class=3D"gmail_default" sty=
le=3D"font-family:arial,sans-serif">I suggest removing</div><div class=3D"g=
mail_default" style=3D"font-family:arial,sans-serif"><span style=3D"font-fa=
mily:Arial,Helvetica,sans-serif">=C2=A0 =C2=A0 import matplotlib.pyplot as =
plt</span><br></div><div class=3D"gmail_default" style=3D"font-family:arial=
,sans-serif"></div><div class=3D"gmail_default" style=3D"font-family:arial,=
sans-serif">completely and not using the `pyplot` interface at all.=C2=A0=
=C2=A0</div><div class=3D"gmail_default" style=3D"font-family:arial,sans-se=
rif"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,sans=
-serif">You already have an instance of a Figure, so you should be able to =
replace</div><div class=3D"gmail_default" style=3D"font-family:arial,sans-s=
erif"><span style=3D"font-family:Arial,Helvetica,sans-serif">=C2=A0 =C2=A0 =
plt.subplots_adjust(hspace=3D0.</span><span style=3D"font-family:Arial,Helv=
etica,sans-serif">4)</span><br></div><div class=3D"gmail_default" style=3D"=
font-family:arial,sans-serif"><span style=3D"font-family:Arial,Helvetica,sa=
ns-serif"><br></span></div><div class=3D"gmail_default" style=3D"font-famil=
y:arial,sans-serif"><span style=3D"font-family:Arial,Helvetica,sans-serif">=
with</span></div><div class=3D"gmail_default" style=3D"font-family:arial,sa=
ns-serif"><span style=3D"font-family:Arial,Helvetica,sans-serif">=C2=A0 =C2=
=A0self.figure.subplots_adjust(hspace=3D0.4)</span></div><div class=3D"gmai=
l_default" style=3D"font-family:arial,sans-serif"><span style=3D"font-famil=
y:Arial,Helvetica,sans-serif"><br></span></div><div class=3D"gmail_default"=
 style=3D"font-family:arial,sans-serif"><span style=3D"font-family:Arial,He=
lvetica,sans-serif"><br></span></div><div class=3D"gmail_default" style=3D"=
font-family:arial,sans-serif"></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">On Sun, Jun 26, 2022 at 12:12 PM <a href=3D"m=
ailto:[email protected]">[email protected]</a> &lt;<a href=3D"mailto:mbrenn=
[email protected]">[email protected]</a>&gt; wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex"><div>Dear all</div><div><br></div><div>I r=
an 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. Howe=
ver, if I uncomment the plt.subplots_adjust(...) line, it hangs at exit.</d=
iv><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>wxPy=
thon version 4.0.7</div><div>matplotlib version 3.5.2</div><div>Debian SID<=
br></div><div><br></div><div>------------------------------------</div><div=
>from numpy import arange, sin, pi<br>import matplotlib<br>matplotlib.use(&=
#39;WXAgg&#39;)<br><br>import matplotlib.pyplot as plt<br><br>from matplotl=
ib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas<br>from =
matplotlib.backends.backend_wx import NavigationToolbar2Wx<br>from matplotl=
ib.figure import Figure<br><br>import wx<br><br>class CanvasPanel(wx.Panel)=
:<br>=C2=A0 =C2=A0 def __init__(self, parent):<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 wx.Panel.__init__(self, parent)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.fig=
ure =3D Figure()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.axes1 =3D self.figure.=
add_subplot(2,1,1)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.axes2 =3D self.figur=
e.add_subplot(2,1,2)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.canvas =3D FigureC=
anvas(self, -1, self.figure)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.sizer =3D =
wx.BoxSizer(wx.VERTICAL)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.sizer.Add(self=
.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self=
.SetSizer(self.sizer)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.Fit()<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ### plt.subplots_adjus=
t(hspace=3D0.4) # &lt;-- This causes trouble!<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 <br>=C2=A0 =C2=A0 def draw(self):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t =3D =
arange(0.0, 3.0, 0.01)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 s =3D sin(2 * pi * t)=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.axes1.plot(t, s)<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 self.axes2.plot(t, -s)<br><br><br>if __name__ =3D=3D &quot;__mai=
n__&quot;:<br>=C2=A0 =C2=A0 app =3D wx.App()<br>=C2=A0 =C2=A0 fr =3D wx.Fra=
me(None, title=3D&#39;test&#39;)<br>=C2=A0 =C2=A0 panel =3D CanvasPanel(fr)=
<br>=C2=A0 =C2=A0 panel.draw()<br>=C2=A0 =C2=A0 fr.Show()<br>=C2=A0 =C2=A0 =
app.MainLoop()</div><div>------------------------------------</div>

<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]" targ=
et=3D"_blank">[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&amp;utm_source=3Dfooter" target=3D"_blank">https=
://groups.google.com/d/msgid/wxpython-users/c2cb8664-bd10-4875-b5c3-cf2d5cd=
a5dbfn%40googlegroups.com</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div><div dir=3D"ltr" class=
=3D"gmail_signature"><div dir=3D"ltr">--Matt=C2=A0<br></div></div></div>

<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/CA%2B7ESbosEj3X_QdBoKqMfgnmPNgO-NbOAZQDLJx2-2cSCC=
NYmw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://group=
s.google.com/d/msgid/wxpython-users/CA%2B7ESbosEj3X_QdBoKqMfgnmPNgO-NbOAZQD=
LJx2-2cSCCNYmw%40mail.gmail.com</a>.<br />

--000000000000dfdfc005e25dddd9--