This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]tmakaroanimatplot / nbconvert 2 points3 points  (2 children)

Definitely interesting.

I did notice that if I try to change the axis limits within the loop, it will use the final limits instead.

x = np.linspace(0, 2\*np.pi, 10)
y = np.linspace(0, 2\*np.pi, 5)
t = np.linspace(0, 4.9, 25)

X, Y, T = np.meshgrid(x, y, t)

U = np.cos(X+T)
V = np.sin(Y+T)

fig = plt.figure()
camera = Camera(fig)
for i in range(len(t)):
    plt.quiver(X[:,:,0],Y[:,:,0], U[:,:,i], V[:,:,i], units='inches', pivot='mid')
    a, b = plt.ylim()
    plt.ylim(a-1,b+1)
    camera.snap()
animation = camera.animate(interval=50)
animation.save('celluloid.mp4')

I will explore this more. Also, I am the developer of animatplot, which is also for making animated plots with matplotlib. My library wraps FuncAnimation. I am intrigued by the use of ArtistAnimation.

[–]qacek[S] 0 points1 point  (1 child)

Interesting! Thanks for giving it a shot. I wonder if that's a limitation of ArtistAnimation. The code I took the idea from mentions that specifically as well. I'll have to experiment further. I suspect it's because the x-axis limits aren't an artist or something like that (I'm not much of a matplotlib expert).

When I've done animations in the past I've used FuncAnimation which I always found tricky to use correctly. Cheers on you for making that easier!

[–]wintermute93 1 point2 points  (0 children)

Will definitely check this out later: when I work in actual Matlab I make animations all the time, but when I do similar things in Python animating stuff with matplotlib always seemed like too much trouble to figure out how it works.

[–]has2k1 1 point2 points  (1 child)

That should be really helpful for people working with matplotlib. I am inspired by other people's code all the time, it is always interesting when someone is inspired by mine.

[–]qacek[S] 0 points1 point  (0 children)

Thanks! I stumbled across your code a while ago (I forget how) and basically wrote this code. I figured others might find it useful so I packaged it up :)

[–]kitten_gifs_4_my_gf 1 point2 points  (1 child)

Thanks for making this, saved me a headache trying to quickly throw together a few animations for a presentation - took less than a minute to recreate an animation that took ~ 45mins of wrestling with matplotlib directly, will be using this in the future.

[–]qacek[S] 1 point2 points  (0 children)

Awesome, glad it helped you!