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

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

On Thu, Jul 23, 2020 at 6:42 AM Matthias Brennwald <[email protected]>
wrote:

> On Do, Jul 23, 2020 at 13:05, Andrea Gavana <[email protected]>
> wrote:
>
> I also have an application that does heavy calculations in a separate
> thread and updates the main plotting window at selected timesteps.
> Depending on the model, I may get between 1 and 100 results per second and
> I have to update the plot with that.
>
>
> Speeding up the plotting part is certainly useful.
>
> However, my question was more related to how it would be possible to avoid
> the situation that the GUI may lock up. I guess the issue is that in my
> code example the calls to wx.CallLater( ...update_the_plot... ) are piling
> up, and therefore the queue is blocking all other code that would be called
> to handle the GUI. Since I am a newbie to wxPython I would be surprised if
> there weren't a few better ways than what I did my example. Maybe there is
> a mechanism that avoids the wx.CallLater(...) from piling up, or something
> else than wx.CallLater(...) entirely.
>

One alternative would be to use a simple Timer that calls a function to
"fetch the latest data and display it".   That can then run at the natural
rate for your GUI client to fetch the data and render that display.   This
approach allows the GUI to be responsive, and not miss any data even if it
does not update exactly once for every single data event.  It also gives
you a convenient method to temporarily pause the display (just have access
to the Timer's stop() and start() methods).

This would hopefully encourage you to design the code that consumes the
data to be in another thread or even a separate process (even on a
different machine) that "gets data from device and posts it", perhaps using
methods like sockets, zeromq, writing to a database, or shared memory and
then have the GUI simply read the latest data from that source.
 Separating *collection* and *display* of the data will probably serve you
well in the end anyway.

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%2B7ESbpN97yRtvKVDBcyUu%3DXUQFspBiH1_BhZWd%3DDMONG%3DqvKQ%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.