[IPython-User] suppress figure rendering in notebook

Brian Granger ellisonbg@gmail....
Mon Jul 16 11:07:31 CDT 2012


John,

On Sun, Jul 15, 2012 at 11:20 AM, John Hunter <jdh2358@gmail.com> wrote:
> I just added support for the ipython display protocol in the
> matplotlib.animations.Animation.save method, so that when you call "save" an
> embedded html movie is put into the notebook
> (https://github.com/matplotlib/matplotlib/pull/1012).

Cool!

> A couple of minor warts became apparent, and I am wondering if there is a
> workaround.  One is that the mpl figure that contains the animation frame is
> also being displayed inline, so that in addition to the embedded movie, the
> last frame of the animation is also rendered as an inline mpl figure.  Is
> there a way to suppress a figure from being rendered?  Conceptually, I'd
> like to be able to do:
>
>     fig = plt.figure();  # semi-colon to suppress rendering

Hmm, the display protocol definitely wasn't designed with this type of
thing in mind, but we could add it.  Not sure if the semicolon would
be easy or not.  We would have to i) add the needed flags to the
display system and display_hook to silence all output and ii) set
those flags (probably method calls) when the parser logic finds the
semicolon.  But, I have a feeling to most natural way of doing this
would be at the cell level.  IOW, the output for the entire cell would
be silenced.  I have a feeling that you are wanting to silence only
some of the output.  For that I would think about creation of function
that can be called to set a silence flag on the mpl inline backend.

> Secondly, it appears that recent versions of chrome and firefox do not
> support native rendering of mp4 movies
> (https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements).
> I hacked webm support into mpl animations so I have something working, but
> I'd like it to also work with more common movie formats.  Since the default
> notebook tour shows examples of embedded mpl4 movies using the <video> html
> tag, I assume these are working for somebody.  But not for me on chrome
> (Chromium 18.0.1025.168 Ubuntu 12.04) or firefox (Mozilla Firefox 13.0.1).
> I did a little googling and installed some of the chrome ffmpeg codecs (sudo
> apt-get install chromium-codecs-ffmpeg-extra) and this does enable me to
> view the default ipython mv4 movie examples, but strangely not movies I am
> creating using mpl via ffmpeg (I can play these using eg mplayer).  My
> _repr_html_ method is returning '<video controls
> src="/files/movies/pcolors.m4v" />' which looks correct to me.  But for some
> reason I am getting the dreaded black box with the triangle play button that
> does noting rather than the movie window with the control.  Not a big deal
> because I have webm working but thought I'd throw it out there in case
> someone has an idea what is going on.

IIRC, Fernando and Chris Kees found these same problems when they
tried to embed movies before.

Cheers,

Brian

>
> # example animation notebook cell with display hook; requires
> https://github.com/matplotlib/matplotlib/pull/1012
>
> import matplotlib.animation as animation
> fig, ax = plt.subplots()
> x = np.arange(-9, 10)
> y = np.arange(-9, 10).reshape(-1, 1)
> base = np.hypot(x, y)
>
> # each frame is a list of matplotlib artists to be animated for the frame;
> here only one image per frame
> frames = []
> for add in np.arange(15):
>     ax.cla()  # clear the last frame
>     im = ax.pcolor(x, y, base + add, norm=plt.Normalize(0, 30))
>     frames.append([im])
>
> im_ani = animation.ArtistAnimation(fig, frames, repeat=False, blit=True)
>
> # Set up formatting for the movie files
> Writer = animation.writers['ffmpeg_file']
>
> # we can force ffmpeg to make webm movies if we use -f webm and no codec.
> # webm works by default on chrome and firefox
> writer = Writer(fps=15, codec='None', extra_args=['-f', 'webm'])
> im_ani.save('movies/im2.webm', writer=writer)
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-User mailing list