You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to make animations using p9 figures, but I end up with matplotlib exceptions. I was wondering whether there is a convenient way to make animations out of plotnine plots.
Here is what I've tried so far:
fromplotnineimport*fromplotnine.dataimport*frommatplotlib.animationimportArtistAnimationimportmatplotlib.pyplotaspltimportnumpyasnpdefplot1(y):
returnplt.scatter(y[:, 0], y[:, 1], c='black'),
defplot2(y):
return (qplot(y[:, 0], y[:, 1], xlab='x', ylab='y') +theme_minimal()).draw(),
# Use mtcars as toy dataX=mtcars[['disp', 'hp']].as_matrix()
# Add little noise to make animation cooldata= [X+np.random.normal(0, 1, (X.shape[0], X.shape[1])) for_inrange(50)]
fig=plt.figure(figsize=(8, 8))
artists= [plot1(x) forxindata]
ani=ArtistAnimation(fig, artists, interval=100, repeat_delay=500)
ani.save('/tmp/animation.mp4')
fig=plt.figure(figsize=(8, 8))
artists= [plot2(x) forxindata]
ani=ArtistAnimation(fig, artists, interval=100, repeat_delay=500)
ani.save('/tmp/animation2.mp4')
Here is the exception I get:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-98cef8b8381e> in <module>()
25 artists = [plot2(x) for x in data]
26 ani = ArtistAnimation(fig, artists, interval=100, repeat_delay=500)
---> 27 ani.save('/tmp/animation2.mp4')
~/.miniconda3/lib/python3.6/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
1055 for anim in all_anim:
1056 # Clear the initial frame
-> 1057 anim._init_draw()
1058 for data in zip(*[a.new_saved_frame_seq()
1059 for a in all_anim]):
~/.miniconda3/lib/python3.6/site-packages/matplotlib/animation.py in _init_draw(self)
1374 # Flush the needed figures
1375 for fig in figs:
-> 1376 fig.canvas.draw_idle()
1377
1378 def _pre_draw(self, framedata, blit):
AttributeError: 'NoneType' object has no attribute 'canvas'
Is there a way to get "proper" artists for ArtistAnimation class?
The text was updated successfully, but these errors were encountered:
I have not tried to do animations, may be this issue can help straighten that out.
The problem with the plot2 function is that, ggplot.draw() returns a figure. That means you get 50 figures, since plotnine creates the figures. When you have a figure you can obtain the artists with figure.get_children(), but I think that is a catch-all for every artist not just those for the data. And, I think you cannot easily move artists from one figure to another.
So, I do not think ArtistAnimation can be used. Need to think of a nice way of going about this.
Hi,
I'm trying to make animations using p9 figures, but I end up with matplotlib exceptions. I was wondering whether there is a convenient way to make animations out of plotnine plots.
Here is what I've tried so far:
Here is the exception I get:
Is there a way to get "proper" artists for ArtistAnimation class?
The text was updated successfully, but these errors were encountered: