绘制多个子图动画 [英] Plotting multiple subplot animations

查看:69
本文介绍了绘制多个子图动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在 2x2 matplotlib 矩阵中绘制四个同步动画.我的代码如下:

I am currently trying to plot four simultaneous animations in a 2x2 matplotlib matrix. My code is as follows:

x1 = np.random.normal(0, 1, 1000)
x2 = np.random.gamma(0, 1.5, 1000)
x3 = np.random.exponential(2, 1000)
x4 = np.random.uniform(0,20, 1000)

import matplotlib.animation as animation
n = 1000
def update(curr):
# check if animation is at the last frame, and if so, stop the animation a
 if curr == n: 
    a.event_source.stop()
 plt.cla()
 fig , ax = plt.subplots(2,2,figsize=(5,3),sharex=False,sharey=False)
 ax[0,1].hist(x1[:curr],bins=50,alpha=0.5,normed=True)
 ax[0,0].hist(x2[:curr],bins=50,alpha=0.5,normed=True)
 ax[1,0].hist(x3[:curr],bins=50,alpha=0.5,normed=True)
 ax[1,1].hist(x4[:curr],bins=50,alpha=0.5,normed=True)

fig , ax=plt.subplots(2,2,figsize=(5,3))
a = animation.FuncAnimation(fig, update, interval=100)

子图由艺术家绘制,但动画从未填充直方图.没有错误解决,Jupyter 将该行标记为完整.知道发生了什么吗?

The subplots are drawn by the Artist, but the animation never fills in the histograms. No error resolves and Jupyter marks the line as complete. Any idea what's happening?

推荐答案

如果你想在你的 jupyter notebook 中看到动画,你需要在你的脚本之前添加 %matplotlib notebook.

You need to add %matplotlib notebook before your script if you want to see the animation inside your jupyter notebook.

https://ipython.readthedocs.io/en/stable/interactive/plotting.html

这篇关于绘制多个子图动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆