1

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, each containing 8 subplots. I do this using animation:

anim = []

anim.append( matplotlib.animation.FuncAnimation(fig_A, updatePlots_A, frames=None, interval=100, repeat=True) )
anim.append( matplotlib.animation.FuncAnimation(fig_B, updatePlots_B, frames=None, interval=100, repeat=True) )

plt.show()

My question is whether it is ok to make two FuncAnimation calls in this way? Is that the most efficient way of handling the plots?

The figures are not very responsive to user input. Moving a figure by dragging it with the mouse is very sluggish.

I've chosen:

frames=None, interval=100

because I want each of my update functions to be called at 10Hz. Will the code achieve this (machine performance permitting)?

I tried using matplotlib.pyplot.pause() instead of FuncAnimation() but found the update rate was then worse, so went back to using FuncAnimation().

Any comments for improvement would be appreciated.

11
  • It's fine to use two FuncAnimations, although you would achive the same with one FuncAnimation which calls a function that then calls both updatePlots functions. The slugghish update rate or lost responsivity is rather due to updating 16 subplots at the same time, I would guess. Depending on what is drawn in them this may take some time. There are some limited means to improve performance in matplotlib animations, but you should look around for them yourself and see if they can be applied to your case. Commented Jul 21, 2017 at 8:42
  • Thanks. I did consider using a single FuncAnimation that calls both updatePlots functions, but FuncAnimation takes a fig object, so I don't know what to do as I have two fig objects. Commented Jul 21, 2017 at 8:48
  • Oh, well, now that you meantion it, it's clear that fig_A is different from fig_B. Sorry for the confusion. But the main argument stays the same: You probably have too many objects that need to be updated. Commented Jul 21, 2017 at 8:52
  • Thanks for your help. Commented Jul 21, 2017 at 9:01
  • 1
    @ThomasKühn Thanks again. For unknown reasons, plt.pause is taking seconds, but I replaced it with fig.canvas.flush_events() and that is much faster. So I think I have a solution now. Commented Jul 21, 2017 at 12:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.