1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider def rx(t): return np.cos(t)/(1+np.sin(t)**2) def ry(t): return np.sin(t)*np.cos(t)/(1+np.sin(t)**2) t = 0 fig,ax1 = plt.subplots(1,1,figsize=(10,6)) plt.subplots_adjust(bottom=0.2) ax1.set_aspect('equal') ax1.set_ylim(-0.5,0.5) ax1.set_xlim(-1.2,1.2) ax1.title.set_text('Parametric curve: Lemniscate of Bernoulli') ax1.grid('on') r, = ax1.plot(rx(t), ry(t),'b', markersize=3) Pnt1, = ax1.plot(rx(t), ry(t),'ro', markersize=6) axt = plt.axes([0.25, 0.1, 0.5, 0.01]) t_slide = Slider(axt,'t',0, 2.0*np.pi,valstep=0.01,valinit=t) def update(val): t = t_slide.val T = np.linspace(0,t,200) r.set_data(rx(T),ry(T)) Pnt1.set_data(rx(t),ry(t)) fig.canvas.draw_idle() t_slide.on_changed(update) plt.show() |
Recent Comments