[IPython-User] suppress figure rendering in notebook

John Hunter jdh2358@gmail....
Sun Jul 15 13:20:26 CDT 2012


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).

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

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.


# 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120715/6fa76448/attachment.html 


More information about the IPython-User mailing list