| 32 | import matplotlib.pyplot as plt |
| 33 | from matplotlib.animation import FuncAnimation |
| 34 | def circle_to_ellipse(): |
| 35 | fig, ax = plt.subplots() |
| 36 | T = np.linspace(0, 2*np.pi, 200) |
| 37 | x = np.cos(T) |
| 38 | y = np.sin(T) |
| 39 | curve, = plt.plot(x,y,'b') |
| 40 | A_values = np.hstack([np.linspace(0.1, 0.9, 100), |
| 41 | np.linspace(0.9, 0.1, 100)]) |
| 42 | def init(): |
| 43 | ax.set_xlim(-1, 1) |
| 44 | ax.set_ylim(-1, 1) |
| 45 | ax.set_aspect('equal') |
| 46 | return curve, |
| 47 | def update(A): |
| 48 | x = A*np.cos(T) |
| 49 | y = np.sin(T) |
| 50 | curve, = plt.plot(x,y,'b') |
| 51 | return curve, |
| 52 | ani = FuncAnimation(fig, update, A_values, |
| 53 | interval=20, # milliseconds |
| 54 | init_func=init, blit=True) |
| 55 | plt.show() |
| 56 | |
| 57 | circle_to_ellipse() |