Skip to content
Advertisement

Matplotlib figure key_event connection after closing window in recreating loop

I have the following minimalistic code that works perfectly fine: a continuous while loop keeps plotting my data and if I press the escape key the plotting stops. Now, if one closes the matplotlib-window a new appears because of the plt.pause command, but now the key_event is not attached anymore. Is there a way to keep the connection of new appearing windows and the key_event?

Code:

JavaScript

Advertisement

Answer

When you close window then it creates new figure and you should use gcf() (get current figure) to assign event to new figure

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement