Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimation using matplotlib with subplots and ArtistAnimation
    primarykey
    data
    text
    <p>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.</p> <p><img src="https://i.stack.imgur.com/zYEoN.png" alt="enter image description here"></p> <p>I keep getting an error: AttributeError: 'list' object has no attribute 'set_visible'. I googled it (as you do) and stumbled across <a href="http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html" rel="noreferrer">http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html</a> 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:</p> <pre><code>#!/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() </code></pre> <p>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.</p> <p>Adrian</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload