Python and update digit in matplotlib

I did a SO search, but did not find the right β€œsolution” for my problem. I run a loop for some data that I want to build. At each step of the loop, I draw a shape using plt.show (). However, since this is a blocking function, I get stuck until I close the window manually and then the cycle continues and the following graph appears.

What I would like to do is bind a keypress event to close the shape and continue the loop (instead of using the mouse for the "X" from the figure).

If this is not possible, I would like to set a timer to close the figure and continue the cycle.

All my problems seem to be related to the fact that plt.show () blocks everything else - in any way about all this?

Some notes on my stories: they use the same axes, but contain a scatter chart, fill fields, and annotations β€” which always change.

Thanks!

+6
source share
1 answer

Try using ion from matplotlib.pyplot :

 import matplotlib.pyplot as pp pp.ion() fig = pp.figure() 

Further information on ion and interactive and non-interactive use is here.

Alternatively, if you want to go with the click of a button, assign a callback

 def moveon(event): pp.close() cid = fig.canvas.mpl_connect('key_press_event', moveon) pp.show() 

The event timer is more complex because the show command blocks, so you probably need to use threads.

+4
source

Source: https://habr.com/ru/post/921868/


All Articles