Skip to content

Instantly share code, notes, and snippets.

@sabopy
Created July 27, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabopy/8001c3b41860afb1f5412b313ae5ab2f to your computer and use it in GitHub Desktop.
Save sabopy/8001c3b41860afb1f5412b313ae5ab2f to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from IPython.display import HTML
u = np.linspace(0.001, 2 * np.pi, 100)
x = 10*np.cos(u)
y = 10*np.sin(u)
x_ = np.linspace(-13,13,100)
fig, ax = plt.subplots(figsize=(6,6),subplot_kw={'aspect': 'equal'})
ax.plot(x,y,'C6-')
p1,=ax.plot([],[],'C7o')
p2,=ax.plot([],[],color='C9')
def update(i):
x0=x[i]
y0=y[i]
y_ = (-x0*x_ +100) / y0
p1.set_xdata(x0)
p1.set_ydata(y0)
p2.set_xdata(x_)
p2.set_ydata(y_)
ax.set_xlim(-12.2, 12.2)
ax.set_ylim(-12.2, 12.2)
ani = animation.FuncAnimation(fig, update, interval = 30, frames = 100)
#ani.save('eli_animation.mp4', writer="ffmpeg",dpi=100)
HTML(ani.to_html5_video())
u = np.linspace(0.001, 2 * np.pi, 100)
x = 10*np.cos(u)
y = 10*np.sin(u)
x_ = np.linspace(-13,13,100)
fig, ax = plt.subplots(figsize=(6,6),subplot_kw={'aspect': 'equal'})
ax.plot(x,y,'C6-')
p1,=ax.plot([],[],'C7o')
p2,=ax.plot([],[])
def update(i):
x0=x[i]
y0=y[i]
y_ = (-x0*x_ +100) / y0
p1.set_xdata(x0)
p1.set_ydata(y0)
ax.plot(x_,y_)
ax.set_xlim(-12.2, 12.2)
ax.set_ylim(-12.2, 12.2)
ani = animation.FuncAnimation(fig, update, interval = 30, frames = 100)
#ani.save('eli_animation.mp4', writer="ffmpeg",dpi=100)
HTML(ani.to_html5_video())
#version
import matplotlib
print(matplotlib.__version__)
print(np.__version__)
3.3.0
1.19.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment