Skip to content

Commit

Permalink
Fixed MPLRenderer anim output
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 16, 2018
1 parent 41e02f1 commit 960284f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion doc/builder
63 changes: 32 additions & 31 deletions holoviews/plotting/mpl/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,9 @@ def __call__(self, obj, fmt='auto'):

if isinstance(plot, tuple(self.widgets.values())):
data = plot()
elif fmt in ['png', 'svg', 'pdf', 'html', 'json']:
with mpl.rc_context(rc=plot.fig_rcparams):
data = self._figure_data(plot, fmt, **({'dpi':self.dpi} if self.dpi else {}))
else:
if sys.version_info[0] == 3 and mpl.__version__[:-2] in ['1.2', '1.3']:
raise Exception("<b>Python 3 matplotlib animation support broken &lt;= 1.3</b>")
with mpl.rc_context(rc=plot.fig_rcparams):
anim = plot.anim(fps=self.fps)
data = self._anim_data(anim, fmt)
data = self._figure_data(plot, fmt, **({'dpi':self.dpi} if self.dpi else {}))

data = self._apply_post_render_hooks(data, obj, fmt)
return data, {'file-ext':fmt,
Expand Down Expand Up @@ -188,31 +182,38 @@ def _figure_data(self, plot, fmt='png', bbox_inches='tight', as_script=False, **
Similar to IPython.core.pylabtools.print_figure but without
any IPython dependency.
"""
fig = plot.state

traverse_fn = lambda x: x.handles.get('bbox_extra_artists', None)
extra_artists = list(chain(*[artists for artists in plot.traverse(traverse_fn)
if artists is not None]))

kw = dict(
format=fmt,
facecolor=fig.get_facecolor(),
edgecolor=fig.get_edgecolor(),
dpi=self.dpi,
bbox_inches=bbox_inches,
bbox_extra_artists=extra_artists
)
kw.update(kwargs)

# Attempts to precompute the tight bounding box
try:
kw = self._compute_bbox(fig, kw)
except:
pass
if fmt in ['gif', 'mp4']:
if sys.version_info[0] == 3 and mpl.__version__[:-2] in ['1.2', '1.3']:
raise Exception("<b>Python 3 matplotlib animation support broken &lt;= 1.3</b>")
with mpl.rc_context(rc=plot.fig_rcparams):
anim = plot.anim(fps=self.fps)
data = self._anim_data(anim, fmt)
else:
fig = plot.state

traverse_fn = lambda x: x.handles.get('bbox_extra_artists', None)
extra_artists = list(chain(*[artists for artists in plot.traverse(traverse_fn)
if artists is not None]))

kw = dict(
format=fmt,
facecolor=fig.get_facecolor(),
edgecolor=fig.get_edgecolor(),
dpi=self.dpi,
bbox_inches=bbox_inches,
bbox_extra_artists=extra_artists
)
kw.update(kwargs)

# Attempts to precompute the tight bounding box
try:
kw = self._compute_bbox(fig, kw)
except:
pass
bytes_io = BytesIO()
fig.canvas.print_figure(bytes_io, **kw)
data = bytes_io.getvalue()

bytes_io = BytesIO()
fig.canvas.print_figure(bytes_io, **kw)
data = bytes_io.getvalue()
if as_script:
b64 = base64.b64encode(data).decode("utf-8")
(mime_type, tag) = MIME_TYPES[fmt], HTML_TAGS[fmt]
Expand Down

0 comments on commit 960284f

Please sign in to comment.