使用matplotlib大选的和ArtistAnimation动画 [英] Animation using matplotlib with subplots and ArtistAnimation

查看:1184
本文介绍了使用matplotlib大选的和ArtistAnimation动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的图像分析,我想创建最终结果的动画,包括2D数据的时间序列和单个像素使得1D地块更新为2D时间序列的阴谋动画的进展。然后在一个插曲并排通过下面的链接具有理想的情况是动画的最终结果的图像进行设置。

I am working on an image analysis and I want to create an animation of the final results that includes the time-sequence of 2D data and a plot of the time sequences at a single pixel such that the 1D plot updates as the 2D animation progresses. Then set them up in a subplot side by side The link below has an image of the end result which would ideally be animated.

我不断收到一个错误:AttributeError的:'名单'对象有没有属性'set_visible。我GOOGLE了它(为你做的)并在<一个偶然href=\"http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html\" rel=\"nofollow\">http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html其中一个家伙鸭拳的code设置set_visible属性。不幸的是,该地块的命令似乎并不具有这样的属性,所以我很茫然,我怎么能产生动画。我已经包含在下面的最小工作示例(注释掉)猴子补丁,以及第二个'IM2',它也注释掉这应该成为任何试图运行code工作。很显然,这将会给你两个2D情节动画。最小工作实施例是如下:

I keep getting an error: AttributeError: 'list' object has no attribute 'set_visible'. I googled it (as you do) and stumbled across http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html where one guy duck punches the code to set the set_visible attribute. Unfortunately, the plot command does not seem to have such an attribute so I am at a loss as to how I can produce the animation. I have included the monkey patch in the minimal working example below (commented out) as well as a second 'im2' that is also commented out which should work for anyone trying to run the code. Obviously it will give you two 2D plot animations. Minimal working example is as follows:

#!/usr/bin/env python

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

#create image with format (time,x,y)
image = np.random.rand(10,10,10)
image2 = np.random.rand(10,10,10)

#setup figure
fig = plt.figure()
ax1=fig.add_subplot(1,2,1)
ax2=fig.add_subplot(1,2,2)

#set up list of images for animation
ims=[]
for time in xrange(np.shape(image)[1]):
    im = ax1.imshow(image[time,:,:])
 #   im2 = ax2.imshow(image2[time,:,:])
    im2 = ax2.plot(image[0:time,5,5])
 #   def setvisible(self,vis): 
 #       for c in self.collections: c.set_visible(vis) 
 #    im2.set_visible = types.MethodType(setvisible,im2,None) 
 #    im2.axes = plt.gca() 

    ims.append([im, im2])

#run animation
ani = anim.ArtistAnimation(fig,ims, interval=50,blit=False)
plt.show()

我也好奇,是否任何人知道的凉爽的方式来突出显示该像素的一维数据是从提取,或者甚至绘制从像素行到最右边的副区,使得它们在某些连接方式。

I was also curious as to whether anyone knew of a cool way to highlight the pixel that the 1D data is being extracted from, or even draw a line from the pixel to the rightmost subplot so that they are 'connected' in some way.

阿德里安

推荐答案

剧情返回艺术家(因此错误是指列表)的列表。这样,您可以拨打剧情 =线图(X1,Y1,X2,Y2,...)

plot returns a list of artists (hence why the error is referring to a list). This is so you can call plot like lines = plot(x1, y1, x2, y2,...).

修改

 im2 = ax2.plot(image[0:time,5,5])

 im2, = ax2.plot(image[0:time,5,5])

添加逗号未包长度的一个列表分为 IM2

至于你的第二个问题,我们试图只有每个线程一个问题上如此如此,请打开一个新的问题。

As for you second question, we try to only have one question per thread on SO so please open a new question.

这篇关于使用matplotlib大选的和ArtistAnimation动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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