This code (coming from here) works well to do some plot, and update with new plots in a for loop:
import numpy as np
from matplotlib import pyplot as plt

plt.ion() # interactive mode on

X = np.arange(-50, 51)
for k in range(1,5):
print k
Y = [x**k for x in X]
plt.plot(X, Y)
It works, but it has 2 (minor) drawbacks:

  • A warning message:
    C:\Python27\lib\site-packages\matplotlib\ MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation)
  • If I close the main plot window during the loop, I get:
    File "C:\Python27\lib\lib-tk\", line 964, in update'update')
    _tkinter.TclError: can't invoke "update" command: application has been destroyed

What's the clean way to do non-blocking plots in a for loop?

View Solution