Re: Possible bug in wxPython or matplotlib.pyplot?

Matthias Brennwald <[email protected]> Sun, 26 Jun 2022 20:26:52 +0200
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
--=-e1Wp4tPOGS6VGC+o+8/l
Content-Type: text/plain; charset="UTF-8"; format=flowed

Hi Matt

Thanks, your suggested fix works perfectly.

Still, there seems to be something wrong, either with what I did in my 
original example, or with matplotlib, or with wxPython. I'd like to 
underststand where the problem is. Any thoughts?

Matthias

On Sun, Jun 26 2022 at 13:20:29 -05:00:00, Matt Newville 
<[email protected]> wrote:
> 
> 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] 
> <mailto:[email protected]> <[email protected] 
> <mailto:[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] 
>> <mailto:[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] 
> <mailto:[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 
> <https://groups.google.com/d/msgid/wxpython-users/CA%2B7ESbosEj3X_QdBoKqMfgnmPNgO-NbOAZQDLJx2-2cSCCNYmw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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/SKK3ER.2A4162ZVW0RE3%40gmail.com.

--=-e1Wp4tPOGS6VGC+o+8/l
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div id=3D"geary-body" dir=3D"auto"><div>Hi Matt</div><div><br></div><div>T=
hanks, your suggested fix works perfectly.</div><div><br></div><div>Still, =
there seems to be something wrong, either with what I did in my original ex=
ample, or with matplotlib, or with wxPython. I'd like to underststand where=
 the problem is. Any thoughts?</div><div><br></div><div>Matthias</div></div=
><div id=3D"geary-quote" dir=3D"auto"><br>On Sun, Jun 26 2022 at 13:20:29 -=
05:00:00, Matt Newville &lt;[email protected]&gt; wrote:<br><block=
quote type=3D"cite"><div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_d=
efault" style=3D"font-family:arial,sans-serif"><br></div></div><div class=
=3D"gmail_default" style=3D"font-family:arial,sans-serif">I suggest removin=
g</div><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif">=
<span style=3D"font-family:Arial,Helvetica,sans-serif">&nbsp; &nbsp; import=
 matplotlib.pyplot as plt</span><br></div><div class=3D"gmail_default" styl=
e=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` int=
erface at all.&nbsp;&nbsp;</div><div class=3D"gmail_default" style=3D"font-=
family:arial,sans-serif"><br></div><div class=3D"gmail_default" style=3D"fo=
nt-family:arial,sans-serif">You already have an instance of a Figure, so yo=
u should be able to replace</div><div class=3D"gmail_default" style=3D"font=
-family:arial,sans-serif"><span style=3D"font-family:Arial,Helvetica,sans-s=
erif">&nbsp; &nbsp; plt.subplots_adjust(hspace=3D0.</span><span style=3D"fo=
nt-family:Arial,Helvetica,sans-serif">4)</span><br></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">with</span></div><div class=3D"gmail_default" style=3D"=
font-family:arial,sans-serif"><span style=3D"font-family:Arial,Helvetica,sa=
ns-serif">&nbsp; &nbsp;self.figure.subplots_adjust(hspace=3D0.4)</span></di=
v><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif"><span=
 style=3D"font-family:Arial,Helvetica,sans-serif"><br></span></div><div cla=
ss=3D"gmail_default" style=3D"font-family:arial,sans-serif"><span style=3D"=
font-family:Arial,Helvetica,sans-serif"><br></span></div><div class=3D"gmai=
l_default" style=3D"font-family:arial,sans-serif"></div><br><div class=3D"g=
mail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jun 26, 2022 at 1=
2:12 PM <a href=3D"mailto:[email protected]">[email protected]</a> &lt;<a h=
ref=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;borde=
r-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Dear all</div><div=
><br></div><div>I ran into an issue with wxPython and matplotlib.pyplot. Pl=
ease 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, i=
t 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>matplotlib version 3.5.2</d=
iv><div>Debian SID<br></div><div><br></div><div>---------------------------=
---------</div><div>from numpy import arange, sin, pi<br>import matplotlib<=
br>matplotlib.use('WXAgg')<br><br>import matplotlib.pyplot as plt<br><br>fr=
om matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanv=
as<br>from matplotlib.backends.backend_wx import NavigationToolbar2Wx<br>fr=
om matplotlib.figure import Figure<br><br>import wx<br><br>class CanvasPane=
l(wx.Panel):<br>&nbsp; &nbsp; def __init__(self, parent):<br>&nbsp; &nbsp; =
&nbsp; &nbsp; wx.Panel.__init__(self, parent)<br>&nbsp; &nbsp; &nbsp; &nbsp=
; self.figure =3D Figure()<br>&nbsp; &nbsp; &nbsp; &nbsp; self.axes1 =3D se=
lf.figure.add_subplot(2,1,1)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.axes2 =3D =
self.figure.add_subplot(2,1,2)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.canvas =
=3D FigureCanvas(self, -1, self.figure)<br>&nbsp; &nbsp; &nbsp; &nbsp; self=
.sizer =3D wx.BoxSizer(wx.VERTICAL)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.siz=
er.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)<br>&nbsp; &nbsp; &nbsp; =
&nbsp; self.SetSizer(self.sizer)<br>&nbsp; &nbsp; &nbsp; &nbsp; self.Fit()<=
br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; ### plt.subp=
lots_adjust(hspace=3D0.4) # &lt;-- This causes trouble!<br>&nbsp; &nbsp; &n=
bsp; &nbsp; <br>&nbsp; &nbsp; def draw(self):<br>&nbsp; &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.plot(t, s)<br>&nbsp; &nb=
sp; &nbsp; &nbsp; self.axes2.plot(t, -s)<br><br><br>if __name__ =3D=3D "__m=
ain__":<br>&nbsp; &nbsp; app =3D wx.App()<br>&nbsp; &nbsp; fr =3D wx.Frame(=
None, title=3D'test')<br>&nbsp; &nbsp; panel =3D CanvasPanel(fr)<br>&nbsp; =
&nbsp; panel.draw()<br>&nbsp; &nbsp; fr.Show()<br>&nbsp; &nbsp; app.MainLoo=
p()</div><div>------------------------------------</div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
wxPython-users" 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&nbsp;<br></div></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
wxPython-users" 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&amp;utm_source=3Dfooter">https://g=
roups.google.com/d/msgid/wxpython-users/CA%2B7ESbosEj3X_QdBoKqMfgnmPNgO-NbO=
AZQDLJx2-2cSCCNYmw%40mail.gmail.com</a>.<br>
</blockquote></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/SKK3ER.2A4162ZVW0RE3%40gmail.com?utm_medium=3Dema=
il&utm_source=3Dfooter">https://groups.google.com/d/msgid/wxpython-users/SK=
K3ER.2A4162ZVW0RE3%40gmail.com</a>.<br />

--=-e1Wp4tPOGS6VGC+o+8/l--