Re: Plotting to a matplotlib / pyplot window does not work

Andrea Gavana <[email protected]>
Newsgroups gmane.comp.python.wxpython
Message-ID <CAEf70bzD0MYPqnmr-vLgmeCnRRzU4+MfcGCgrunpyWfQ-rzNcQ@mail.gmail.com>
Hi,

On Mon, 20 Jul 2020 at 22.42, Matthias Brennwald <[email protected]> wrote:

> On Mo, Jul 20, 2020 at 18:26, Andrea Gavana <[email protected]>
> wrote:
>
> Your instrument class is 2,263 lines long. Kind of hard to go through it
> and find what wrong for those of us who are not acquainted with your code,
> isn’t it?
> I use Matplotlib with wxPython all the time and I never had any problems.
> You should probably try and create a small runnable sample that reproduces
> the problem; also, If you are using  separate threads you haVe to be
> especially careful when it comes to communicating with the GUI part in
> wxPython. Only the main thread can access GUI stuff (meaning the thread the
> creates the GUI), and communications from other threads can be achieved
> using wx.CallAfter, wx.PostEvent, PubSub, etc...
>
>
> I didn't expect anyone to go through 2263 lines -- that would be crazy! I
> just wanted to provide some background of what I am working with.
>
> I made a "minimal example" that illustrates what I am trying to do, and
> hopefully someone can point out why it does not work as intended (I
> attached the file, I hope the attachment goes through the mailing list).
> The example should show a pyplot window on the screen, which shows the data
> being collected from the measurement instrument (one new data point every
> second). However, the window does not show up. Also, I have to use
> wx.CallAfter to update the pyplot window in order avoid crashing, although
> I don't think the pyplot window is part of the wxPython world.
>
> Any insights would be very welcome!
>


I can see now what you’re trying to do. I’ve never encountered this
approach as normally what you do is embed a Matplotlib figure into a
wxPython window (or TK or QT or GTK window) instead of relying on
Matplotlib.pyplot.

I don’t know what is your default Matplotlib backend for figures, but my
guess is that the wxpython mainloop and the backend mainloop are somehow
interfering with one another, so that may be a reason for your plot not
working.

A relatively straightforward solution is to embed your plot in a wxPython
window and update the plot from a thread when new data becomes available.
See for example:

https://matplotlib.org/3.1.0/gallery/user_interfaces/embedding_in_wx2_sgskip.html

And all the other embedding_in_wx examples - there are 5 of them if I’m not
mistaken.

Andrea.

-- 
> 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/Z5CSDQ.XWF1KXD1QEOT3%40gmail.com
> <https://groups.google.com/d/msgid/wxpython-users/Z5CSDQ.XWF1KXD1QEOT3%40gmail.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/CAEf70bzD0MYPqnmr-vLgmeCnRRzU4%2BMfcGCgrunpyWfQ-rzNcQ%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.