matplotlib plot interactive

Solutions on MaxInterview for matplotlib plot interactive by the best coders in the world

showing results for - "matplotlib plot interactive"
Serena
04 Mar 2016
1# Note: plot will be frozen when running with python console
2import matplotlib
3import matplotlib.pyplot as plt
4matplotlib.use("TkAgg")
5import numpy as np
6
7x = np.linspace(0, 6*np.pi, 100)
8y = np.sin(x)
9
10plt.ion()
11
12fig = plt.figure()
13ax = fig.add_subplot(111)
14line1, = ax.plot(x, y, 'r-')
15plt.draw()  # the line can be deleted
16
17for phase in np.linspace(0, 10*np.pi, 500):
18    line1.set_ydata(np.sin(x + phase))
19    plt.draw()
20    plt.pause(0.02)
21
22plt.ioff()
23plt.show()