创建条形图容器和动画
使用 plt.hist
可以让我们获得一个 BarContainer
实例,它是 Rectangle
实例的集合。我们使用 FuncAnimation
来设置动画。
## Using plt.hist allows us to get an instance of BarContainer, which is a
## collection of Rectangle instances. Calling prepare_animation will define
## animate function working with supplied BarContainer, all this is used to setup FuncAnimation.
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.
ani = animation.FuncAnimation(fig, animate, 50, repeat=False, blit=True)
plt.show()