Animation using matplotlib with subtitles and ArtistAnimation

I am working on image analysis and I want to create an animation of the final results, which includes a time sequence of 2D data and a graph of time sequences on one pixel, so that the 1st graph is updated as the 2D animation progresses. Then install them in the subtitle side by side. The link below contains an image of the final result, which ideally should be animated.

enter image description here

I get the error all the time: AttributeError: the 'list' object does not have the 'set_visible' attribute. I searched for it (like you) and came across http://matplotlib.1069221.n5.nabble.com/Matplotlib-1-1-0-animation-vs-contour-plots-td18703.html , where one guy duck hits by code to set the set_visible attribute. Unfortunately, the plot command does not have such an attribute, so I donโ€™t understand how I can create an animation. I included the monkey patch in the minimum working example below (commented out), as well as the second โ€œim2โ€, which is also commented out, which should work for anyone trying to run the code. Obviously, this will give you two 2D plot animations. Minimum working example:

#!/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 if anyone knew of a cool way to extract a pixel from which 1D data is extracted, or even draw a line from the pixel to the right-most subtask so that they are โ€œconnectedโ€ in some way.

Adrian

+6
source share
1 answer

plot returns a list of executors (therefore, the error refers to the list). This means that you can call plot as lines = plot(x1, y1, x2, y2,...) .

Change

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

to

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

Adding a comma does not pack a single list of lengths in im2

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

+15
source

Source: https://habr.com/ru/post/950243/


All Articles