Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating the x-axis values using matplotlib animation
    primarykey
    data
    text
    <p>I am trying to use <code>matplotlib.ArtistAnimation</code> to animate two subplots. I want the x-axis to increase in value as the animation progresses, such that the total length of the animation is 100 but at any time the subplot is only presenting me with the time values from 0-24 and then iterates up to 100.</p> <p>A great example is given <a href="http://www.roboticslab.ca/matplotlib-animation/" rel="nofollow noreferrer">here</a>. The link uses <code>FuncAnimation</code> and updates the x-axis labels in a rolling fashion using <code>plot().axes.set_xlim()</code> and incrementing the x-values. The code is available via the link below the YouTube video in the link provided.</p> <p>I have appended code below that shows my attempts to replicate these results but the x-limits seem to take on their final values instead of incrementing with time. I have also tried incrementing the solution (as opposed to the axis) by only plotting the values in the window that will be seen in the subplot, but that does not increment the x-axis values. I also tried to implement autoscaling but the x-axis still does not update.</p> <p>I also found <a href="https://stackoverflow.com/questions/15438367/updating-axis-limits-while-working-with-artistanimation">this question</a> which is virtually the same problem, but the question was never answered.</p> <p>Here is my code:</p> <pre><code>import matplotlib.pylab as plt import matplotlib.animation as anim import numpy as np #create image with format (time,x,y) image = np.random.rand(100,10,10) #setup figure fig = plt.figure() ax1=fig.add_subplot(1,2,1) ax2=fig.add_subplot(1,2,2) #set up viewing window (in this case the 25 most recent values) repeat_length = (np.shape(image)[0]+1)/4 ax2.set_xlim([0,repeat_length]) #ax2.autoscale_view() ax2.set_ylim([np.amin(image[:,5,5]),np.amax(image[:,5,5])]) #set up list of images for animation ims=[] for time in xrange(np.shape(image)[0]): im = ax1.imshow(image[time,:,:]) im2, = ax2.plot(image[0:time,5,5],color=(0,0,1)) if time&gt;repeat_length: lim = ax2.set_xlim(time-repeat_length,time) ims.append([im, im2]) #run animation ani = anim.ArtistAnimation(fig,ims, interval=50,blit=False) plt.show() </code></pre> <p>I only want the second subplot (<code>ax2</code>) to update the x-axis values.</p> <p>Any help would be much appreciated.</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.
 

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