From 600a0ce0657ae6f9de449cd4099102a09e234e1d Mon Sep 17 00:00:00 2001 From: baskrahmer Date: Mon, 13 May 2024 14:51:48 +0200 Subject: [PATCH] Add animation example --- examples/image/matplotlib_example.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/image/matplotlib_example.py diff --git a/examples/image/matplotlib_example.py b/examples/image/matplotlib_example.py new file mode 100644 index 00000000000..2b9ee5c4690 --- /dev/null +++ b/examples/image/matplotlib_example.py @@ -0,0 +1,25 @@ +""" +Example using animations +=============================== +""" +# %% +# Example of making sliders in Matplotlib (source: https://sphinx-gallery.github.io/stable/auto_examples/plot_8_animations.html) + +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +# Adapted from +# https://matplotlib.org/gallery/animation/basic_example.html + + +def _update_line(num): + line.set_data(data[..., :num]) + return (line,) + + +fig, ax = plt.subplots() +data = np.random.RandomState(0).rand(2, 25) +(line,) = ax.plot([], [], "r-") +ax.set(xlim=(0, 1), ylim=(0, 1)) +ani = animation.FuncAnimation(fig, _update_line, 25, interval=100, blit=True) \ No newline at end of file