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

David Aldrich David.Aldrich at EMEA.NEC.COM
Fri Jul 21 09:33:27 EDT 2017


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



More information about the Matplotlib-users mailing list