Today I upgraded matplotlib to version 2.0.2, after not upgrading for possibly 3 years.
Now I have the problem that in interactive plots the window always comes to t
It is April 2019 and the mypause() function (copied from the upto date pyplot implementation) for Matplotlib 3.0.3 should look more like
import time
import matplotlib.pyplot as plt
def mypause(interval):
manager = plt._pylab_helpers.Gcf.get_active()
if manager is not None:
canvas = manager.canvas
if canvas.figure.stale:
canvas.draw_idle()
#plt.show(block=False)
canvas.start_event_loop(interval)
else:
time.sleep(interval)
After some testing (Qt5 backend/Spyder/Windows 7 64bit) the calls that do the trick for me are:
#plt.pause(0.001) #Brings plot to foreground
#fig.canvas.draw() #Does not work
#plt.draw_all() #Does not work
#plt.draw() #Does not work
#fig.canvas.flush_events() #Updates only if I click the figure
#import time; time.sleep(0.001) #Does not help flush_events()
#fig.canvas.draw_idle() #Does not work by itself
#fig.canvas.start_event_loop(0.001) #Does not work by itself
#mypause(0.001) #Works!
#Works!
fig.canvas.draw_idle()
fig.canvas.start_event_loop(0.001)
Were fig is your figure object. Either of both alone didn't work in my case. According to the animation documentation this is essentially what FuncAnimation does.