Skip to content

DOC: add example of spinning circle icon animation #24448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
49 changes: 49 additions & 0 deletions examples/animation/spinning_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
=========================
Spinning circle animation
=========================

This example shows how to create an animated spinning circle loading icon.
"""

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})

ax.axis('off')

lines = ax.vlines(
np.radians(np.arange(0, 360, 30)),
0.5,
1,
lw=17,
colors=np.linspace(0.15, 0.85, 12, dtype=str),
capstyle='round',
)

ax.set_rmax(1.1) # make round capstyle on outside visible

def update(*args):
new_colors = np.roll(lines.get_colors(), shift=-1, axis=0)
lines.set_color(new_colors)
return lines,


ani = animation.FuncAnimation(
fig,
update,
interval=100)

plt.show()

#############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.axes.Axes.vlines` / `matplotlib.pyplot.vlines`
# - `matplotlib.animation.FuncAnimation`