A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://matplotlib.org/devdocs/devel/../api/_as_gen/../../gallery/animation/animated_histogram.html below:

Animated histogram — Matplotlib 3.11.0.dev1208+g1c3e0438cb documentation

Animated histogram#

Use histogram's BarContainer to draw a bunch of rectangles for an animated histogram.

To animate the histogram, we need an animate function, which generates a random set of numbers and updates the heights of rectangles. The animate function updates the Rectangle patches on an instance of BarContainer.

Using hist() allows us to get an instance of BarContainer, which is a collection of Rectangle instances. Since FuncAnimation will only pass the frame number parameter to the animation function, we use functools.partial to fix the bar_container parameter.

# Output generated via `matplotlib.animation.Animation.to_jshtml`.

fig, ax = plt.subplots()
_, _, bar_container = ax.hist(data, HIST_BINS, lw=1,
                              ec="yellow", fc="green", alpha=0.5)
ax.set_ylim(top=55)  # set safe limit to ensure that all data is visible.

anim = functools.partial(animate, bar_container=bar_container)
ani = animation.FuncAnimation(fig, anim, 50, repeat=False, blit=True)
plt.show()

Tags: plot-type: histogram component: animation

Total running time of the script: (0 minutes 11.734 seconds)

Gallery generated by Sphinx-Gallery


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4