[Matplotlib-users] Why is flush_events() taking longer than expected?

Thomas Caswell tcaswell at gmail.com
Mon Jul 31 08:53:06 EDT 2017


Exactly what `flush_events` is doing depends on the backend, however I
suspect that in most cases the events are handled in a process-level
singleton so both calls are talking to event queue so the first one does
all the work and the second one finds and empty queue, declares victory and
returns.  To test this switch the A/B order, I expect the first one to be
slow in either case.

As to why it is going slow, I suspect it is the text on your 16 axes.  To
get the speed you want you are probably are going to want to use 'blitting'
which is a way of only re-drawing what has changed (rather than
everything).  See
https://matplotlib.org/api/animation_api.html#funcanimation for more
details.

Tom

On Tue, Jul 25, 2017 at 11:26 AM David Aldrich <David.Aldrich at emea.nec.com>
wrote:

> Hi Ben
>
>
>
> >When you say first and second flush_events(), do you mean the
>
> >first and second iterations, or fig_A and fig_B?
>
>
>
> The latter:
>
>
>
>     fig_A.canvas.flush_events()     ß 350ms
>     fig_B.canvas.flush_events()     ß 1ms
>
>
>
> These timings repeat on each iteration.
>
>
>
> Best regards
>
>
>
> David
>
>
>
> *From:* Benjamin Root [mailto:ben.v.root at gmail.com]
> *Sent:* 25 July 2017 15:46
> *To:* David Aldrich <David.Aldrich at EMEA.NEC.COM>
> *Cc:* matplotlib-users at python.org
> *Subject:* Re: [Matplotlib-users] Why is flush_events() taking longer
> than expected?
>
>
>
> When you say first and second flush_events(), do you mean the first and
> second iterations, or fig_A and fig_B?
>
> Ben Root
>
>
>
> On Fri, Jul 21, 2017 at 9:33 AM, David Aldrich <David.Aldrich at emea.nec.com>
> wrote:
>
> Hi
>
> I am using Matplotlib 2.0.2 in a Python 3.6 script on Windows 10 to plot
> data received over a network connection. New data arrives 4 times per
> second. I need to update two figures fig_A and fig_B, each containing 8
> subplots. The hardware is a fast i7 laptop.
>
> My main execution loop is:
>
> plt.draw()
>
> while (True):
>     fig_A.canvas.flush_events()
>     fig_B.canvas.flush_events()
>     updatePlots()                          # Polls socket for data and
> updates scatter collections
>     fig_A.canvas.draw_idle()
>     fig_B.canvas.draw_idle()
>
> plt.waitforbuttonpress()
>
> I have timed the code and found that the first flush_events() call in the
> loop takes 350ms. The second flush_events() call takes <1ms.
> 350ms seems very long and is restricting the update rate.
>
> Why might flush_events() be taking so long?
>
> (I have not changed the backend from the default, which I believe is
> TkAgg).
>
> Best regards
>
> David
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
>
>
>
>
> Click here
> <https://www.mailcontrol.com/sr/HdU0jnqYd33GX2PQPOmvUiOFufhVdryLTKI5fnw3hQXAeY!z4oAmQUowjoeq+mdHW6eN7GuMFmZOzrnJmt4uGw==>
> to report this email as spam.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170731/9ed191a9/attachment.html>


More information about the Matplotlib-users mailing list