Skip to content

[Doc]: add animation examples to show animated subplots #23909

@story645

Description

@story645

Documentation Link

https://matplotlib.org/devdocs/gallery/animation/index.html

Problem

Figured it'd be useful to have at least one example in the docs to show that it's possible and encourage the use of the OO paradigm. There used to be a subplot example, but that was back when it was overly complicated to do animated subplots. it was removed in #10125

Suggested improvement

Add a new example showing how animation on subplots work. I originally thought of merging existing examples but they all feel overly complicated so I think this should be super simple, like 3 plots: sine/cosine/tangent and two lines each in the style of https://matplotlib.org/devdocs/gallery/animation/simple_anim.html#sphx-glr-gallery-animation-simple-anim-py

I was thinking something like this, but if there's an easier or alternative, we should probably show that (too/instead of):

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

fig, (ax1, ax2, ax3) = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)
line1, = ax1.plot(x, np.sin(x))
line2, = ax2.plot(x, np.cos(x))
line3, = ax3.plot(x, np.tan(x))

def animate(i):
    line1.set_ydata(np.sin(x + i / 50))  # update the data.
    line2.set_ydata(np.sin(x + i / 50)) 
    line3.set_ydata(np.sin(x + i / 50)) 
    return [line1, line2, line3]


ani = animation.FuncAnimation(
    fig, animate, interval=20, blit=True, save_count=50)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions