在ipython笔记本中的动画图形 [英] Animated graphs in ipython notebook

查看:221
本文介绍了在ipython笔记本中的动画图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法制作动画图表。例如,显示相同的图表,具有不同的参数。



例如是SAGE笔记本,可以写:

  a = animate([circle((i,i),1-1 /(i + 1),hue = i / 10)for s in srange(0,2,0.2) ],
xmin = 0,ymin = 0,xmax = 2,ymax = 2,figsize = [2,2])
a.show()


解决方案

更新日期:2014年1月



Jake Vanderplas为matplotlib动画创建了一个基于Javascript的包,,以获得更完整的描述和示例。
历史回答(请参阅更正的支持者)



是的,Javascript更新尚未正确保存图像框架,因此有闪烁,但你可以使用这种技术做一些非常简单的事情:

 导入时间,来自IPython的sys 
。 display import clear_output
f,ax = plt.subplots()

for i in range(10):
y = i / 10 * sin(x)
ax。 plot(x,y)
time.sleep(0.5)
clear_output()
display(f)
ax.cla()#如果你想要关闭它积累情节
plt.close()


Is there a way of creating animated graphs. For example showing the same graph, with different parameters.

For example is SAGE notebook, one can write:

a = animate([circle((i,i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)], 
            xmin=0,ymin=0,xmax=2,ymax=2,figsize=[2,2])
a.show()

解决方案

Update: January 2014

Jake Vanderplas has created a Javascript-based package for matplotlib animations available here. Using it is as simple as:

 # https://github.com/jakevdp/JSAnimation
 from JSAnimation import examples
 examples.basic_animation()

See his blog post for a more complete description and examples. Historical answer (see goger for a correction)

Yes, the Javascript update does not correctly hold the image frame yet, so there is flicker, but you can do something quite simple using this technique:

import time, sys
from IPython.display import clear_output
f, ax = plt.subplots()

for i in range(10):
  y = i/10*sin(x) 
  ax.plot(x,y)
  time.sleep(0.5)
  clear_output()
  display(f)
  ax.cla() # turn this off if you'd like to "build up" plots
plt.close()

这篇关于在ipython笔记本中的动画图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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