From fb5a043f5ccd7e6ec3dc5fed4d8e83a22f98e50d Mon Sep 17 00:00:00 2001 From: Aschauer Date: Mon, 14 Nov 2022 15:37:19 +0100 Subject: [PATCH 1/3] DOC: add spinning circle icon animation example --- examples/animation/spinning_circle.py | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/animation/spinning_circle.py diff --git a/examples/animation/spinning_circle.py b/examples/animation/spinning_circle.py new file mode 100644 index 000000000000..aea0eafa8f97 --- /dev/null +++ b/examples/animation/spinning_circle.py @@ -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` From b947e14a56f4479d844594f4240ad99bc68c825f Mon Sep 17 00:00:00 2001 From: Johannes Aschauer <38501948+joAschauer@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:52:03 +0100 Subject: [PATCH 2/3] return sequence af artists in update function Co-authored-by: Thomas A Caswell --- examples/animation/spinning_circle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/animation/spinning_circle.py b/examples/animation/spinning_circle.py index aea0eafa8f97..0f18a94f1265 100644 --- a/examples/animation/spinning_circle.py +++ b/examples/animation/spinning_circle.py @@ -28,7 +28,7 @@ def update(*args): new_colors = np.roll(lines.get_colors(), shift=-1, axis=0) lines.set_color(new_colors) - return lines + return lines, ani = animation.FuncAnimation( From 5f930d48b1b16de5a1950e81182d175d810eb54d Mon Sep 17 00:00:00 2001 From: Aschauer Date: Mon, 14 Nov 2022 16:00:01 +0100 Subject: [PATCH 3/3] trim trailing whitespaces --- examples/animation/spinning_circle.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/animation/spinning_circle.py b/examples/animation/spinning_circle.py index 0f18a94f1265..bf8ff08a4477 100644 --- a/examples/animation/spinning_circle.py +++ b/examples/animation/spinning_circle.py @@ -16,8 +16,8 @@ lines = ax.vlines( np.radians(np.arange(0, 360, 30)), - 0.5, - 1, + 0.5, + 1, lw=17, colors=np.linspace(0.15, 0.85, 12, dtype=str), capstyle='round', @@ -32,7 +32,7 @@ def update(*args): ani = animation.FuncAnimation( - fig, + fig, update, interval=100)