Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion galleries/users_explain/animations/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.animation as animation
from IPython.display import HTML

# %%
# Animation classes
Expand Down Expand Up @@ -131,6 +131,33 @@ def update(frame):
ani = animation.FuncAnimation(fig=fig, func=update, frames=40, interval=30)
plt.show()

# %%
# Animations in Jupyter Notebooks
# ===============================
#
# Animations can also be displayed inside Jupyter notebooks using HTML rendering.
# This allows interactive playback controls directly in the notebook.
#
# Example:


fig, ax = plt.subplots()
x = np.linspace(0, 2*np.pi)
line, = ax.plot(x, np.sin(x))
title = ax.set_title("Frame 0")

FRAMES = 50


def animate(i):
phi = 2 * np.pi * i / FRAMES
line.set_data(x, np.sin(x - phi))
title.set_text(f"Frame {i}, Phase = {phi:.2f}")
return (line,)

ani = animation.FuncAnimation(fig, animate, frames=FRAMES)
plt.close(fig)
HTML(ani.to_jshtml(fps=20))

# %%
# ``ArtistAnimation``
Expand Down
Loading