Skip to content

Instantly share code, notes, and snippets.

@sabopy
Created July 26, 2020 05:56
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/eb2579d2207bd89ea4946ac557bba833 to your computer and use it in GitHub Desktop.
Save sabopy/eb2579d2207bd89ea4946ac557bba833 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
import matplotlib.animation as animation
from IPython.display import HTML
num = 250
ells = [Ellipse(xy=np.random.rand(2) * 10,
width=np.random.rand(), height=np.random.rand(),
angle=np.random.rand() * 360)
for i in range(num)]
fig, ax = plt.subplots(figsize=(6,6),subplot_kw={'aspect': 'equal'})
def update(num):
ax.add_artist(ells[num])
ells[num].set_clip_box(ax.bbox)
ells[num].set_alpha(np.random.rand())
ells[num].set_facecolor(np.random.rand(3))
ells[num].set_clip_on(False)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.axis('off')
ani = animation.FuncAnimation(fig, update, interval = 30, frames = 250)
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