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

Matt Newville <[email protected]>
Newsgroups gmane.comp.python.wxpython
Message-ID <CA+7ESbromE1hfKSaeizra7ToGU=bwrFqjCL6tc6hLuZT7vW3ow@mail.gmail.com>
Hi Matthias,


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

> I am trying to to make a wxPython program that controls a measurement
> instrument. The access to the instrument happens via a Python class. That
> class configures a matplotlib / pyplot window, where the measured data are
> plotted. In the wxPython application, the data acquisition (and hence the
> plotting) happens in a thread that is separate from the GUI, because this
> is a slow and long-running process that must not block the GUI.
>
> If I use this class from within my wxPython application, the data plotting
> does not work. Plotting works fine if I use the instrument class without
> wxPython.
>
> (The instrument class is here:
> https://github.com/brennmat/ruediPy/blob/master/python/classes/rgams_SRS.py
> )
>
> Any thoughts what's going on? Any clues what to check or where to look for
> the reason why the  combination of matplotlib/pyplot with wxPython not work
> in my case?
>

As Andrea says, that is sort of a lot of code to expect someone to sift
through.  I do notice that you specifically set the TkAgg backend for
matplotlib and then use this with matplotlib.pyplot and its pyplot.ion()
interface.
I think that would need to have access to the Tk event loop and poke it
occasionally for the plot to update.

For reference or perhaps encouragement, I can tell you that I display live
data from scientific instruments basically full time using wxPython and
matplotlib (as well as wxPython and its device context for bitmap images).
Depending on the types of plots and displays you are using, you might find
wxmplot (https://github.com/newville/wxmplot/) useful.  This is essentially
a wrapping in wxPython of matplotlib's 2D line plots  ("plot") and image
displays ("imshow").   The examples include a simple strip-chart and a test
of scrolling through a set of images that might help give some ideas even
if it does not exactly fit your needs.

As Andrea says, how your data from your instruments arrive into your
program can also impact how you need to work with event loops.   The
distributed experimental control system I use relies on callbacks from the
control system event loop (like, within the C library which we load in
python with ctypes).  That means that we use wx.CallAfter in essentially
every "control system event handler" to post data from our control system
threads into the main GUI thread.  To be clear, this works just fine, but
it might be the sort of thing that you need to pay attention to in order to
get a working and responsive live update of images in your application.

Hope that helps,

--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%2B7ESbromE1hfKSaeizra7ToGU%3DbwrFqjCL6tc6hLuZT7vW3ow%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.