Skip to content

Instantly share code, notes, and snippets.

@sabopy
Created August 21, 2020 12:06
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/1e9451c85125026aa52c75a81df1021e to your computer and use it in GitHub Desktop.
Save sabopy/1e9451c85125026aa52c75a81df1021e to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon
import matplotlib.animation as animation
from IPython.display import HTML
fig, ax = plt.subplots(figsize=(6,6),subplot_kw={'aspect': 'equal'})
arttists=[]
def update(num):
if len(arttists)>0:
arttists.pop().remove()
cp=CirclePolygon(xy=(0,0), radius=5, resolution=num+3,fc="C2",alpha=0.5)
art=ax.add_artist(cp)
arttists.append(art)
ax.set_title("resolution="+str(num+3)+"")
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.grid()
ax.set_axisbelow(True)
ani = animation.FuncAnimation(fig, update, interval = 200, frames = 28)
ani.save('cp_animation.mp4', writer="ffmpeg",dpi=120)
HTML(ani.to_html5_video())
fig, ax = plt.subplots(figsize=(6,6),subplot_kw={'aspect': 'equal'})
def update(num):
cp=CirclePolygon(xy=(0,0), radius=5, resolution=num+3,fc="C6",alpha=.1)
art=ax.add_artist(cp)
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.grid()
ax.set_axisbelow(True)
ani = animation.FuncAnimation(fig, update, interval = 200, frames = 28)
ani.save('cp_animation2.mp4', writer="ffmpeg",dpi=120)
HTML(ani.to_html5_video())
#version
import matplotlib
print(matplotlib.__version__)
3.3.1
print(np.__version__)
1.19.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment