Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfeabab

Browse files
committed
Make Animation._repr_html_ more useful by default
While `Animation` does define `_repr_html_`, it does nothing by default since `animation.html` is 'none'. The 'html5' option is the best, but it requires FFmpeg to be installed. So introduce a new 'auto' option that picks either one depending on what's available, and make it the default.
1 parent 3058ff0 commit cfeabab

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

lib/matplotlib/animation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,13 @@ def to_jshtml(self, fps=None, embed_frames=True, default_mode=None):
13991399
def _repr_html_(self):
14001400
"""IPython display hook for rendering."""
14011401
fmt = mpl.rcParams['animation.html']
1402+
if fmt == 'none':
1403+
return
1404+
if fmt == 'auto':
1405+
if writers.is_available(mpl.rcParams['animation.writer']):
1406+
fmt = 'html5'
1407+
else:
1408+
fmt = 'jshtml'
14021409
if fmt == 'html5':
14031410
return self.to_html5_video()
14041411
elif fmt == 'jshtml':

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,11 @@
825825
## ***************************************************************************
826826
## * ANIMATION *
827827
## ***************************************************************************
828-
#animation.html: none # How to display the animation as HTML in
829-
# the IPython notebook:
830-
# - 'html5' uses HTML5 video tag
831-
# - 'jshtml' creates a JavaScript animation
828+
#animation.html: html5 # How to display the animation as HTML in the IPython notebook:
829+
# - 'none' displays nothing
830+
# - 'html5' uses HTML5 video tag
831+
# - 'jshtml' creates a JavaScript animation
832+
# - 'auto' picks the best available option
832833
#animation.writer: ffmpeg # MovieWriter 'backend' to use
833834
#animation.codec: h264 # Codec to use for writing movie
834835
#animation.bitrate: -1 # Controls size/quality trade-off for movie.

lib/matplotlib/rcsetup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ def _convert_validator_spec(key, conv):
14481448
"keymap.copy": validate_stringlist,
14491449

14501450
# Animation settings
1451-
"animation.html": ["html5", "jshtml", "none"],
1451+
"animation.html": ["auto", "html5", "jshtml", "none"],
14521452
# Limit, in MB, of size of base64 encoded animation in HTML
14531453
# (i.e. IPython notebook)
14541454
"animation.embed_limit": validate_float,
@@ -3354,11 +3354,13 @@ class _Subsection:
33543354
_Section("Animation"),
33553355
_Param(
33563356
"animation.html",
3357-
default="none",
3358-
validator=["html5", "jshtml", "none"],
3359-
description="How to display the animation as HTML in the IPython notebook: "
3360-
"- 'html5' uses HTML5 video tag "
3361-
"- 'jshtml' creates a JavaScript animation"
3357+
default="auto",
3358+
validator=["auto", "html5", "jshtml", "none"],
3359+
description="How to display the animation as HTML in the IPython notebook:\n"
3360+
"- 'auto' picks the best available option\n"
3361+
"- 'html5' uses HTML5 video tag\n"
3362+
"- 'jshtml' creates a JavaScript animation\n"
3363+
"- 'none' displays nothing"
33623364
),
33633365
_Param(
33643366
"animation.writer",

0 commit comments

Comments
 (0)