interactive plots with matplotlib code example

Example: matplotlib plot interactive

# Note: plot will be frozen when running with python console
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("TkAgg")
import numpy as np

x = np.linspace(0, 6*np.pi, 100)
y = np.sin(x)

plt.ion()

fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x, y, 'r-')
plt.draw()  # the line can be deleted

for phase in np.linspace(0, 10*np.pi, 500):
    line1.set_ydata(np.sin(x + phase))
    plt.draw()
    plt.pause(0.02)

plt.ioff()
plt.show()