Render
This is done through rendering the figure first and then reload it in a FuncAnimation with imshow. Therefore the zoom function is limited to the resolution of the figure.
[1]:
import matplotlib.pyplot as plt
import numpy as np
import tqdm
from smpl import animation, plot
live-render
[2]:
%matplotlib notebook
plt.ioff()
def update(a):
plot.function(lambda x: a * x**2, xmin=0, xmax=5, init=True, tight=False)
ani = animation.animate(
update=update, frames=np.linspace(0, 10, 200), interval=10, blit=True
)
plt.show()
pre-render
[3]:
%matplotlib notebook
plt.ioff()
for a in tqdm.tqdm(np.linspace(0, 10, 200)):
# no need to bind a here since the lambda is only evaluated in the function
plot.function(lambda x: a * x**2, xmin=0, xmax=5, init=True, tight=False)
animation.frame()
# ani.save("test.gif")
ani = animation.animate(interval=10, blit=True)
plt.show()
100%|██████████| 200/200 [00:02<00:00, 93.23it/s]
Save
[4]:
ani.save("test.gif")
MovieWriter ffmpeg unavailable; using Pillow instead.
/home/docs/checkouts/readthedocs.org/user_builds/smpl/envs/v1.5.4/lib/python3.12/site-packages/matplotlib/animation.py:908: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you output the Animation using `plt.show()` or `anim.save()`.
warnings.warn(
[5]:
import numpy as np
from smpl import animation, plot
for a in np.linspace(0, 10, 200):
# no need to bind a here since the lambda is only evaluated in the function
plot.function(lambda x: a * x**2, xmin=0, xmax=5, init=True, tight=False)
animation.frame()
ani = animation.animate(interval=10, blit=True)
ani.widget_gif()
MovieWriter ffmpeg unavailable; using Pillow instead.
[5]:
[ ]:
[ ]:
[ ]: