diff --git a/holoviews/plotting/mpl/element.py b/holoviews/plotting/mpl/element.py index 08e126f995..8b1124d1dc 100644 --- a/holoviews/plotting/mpl/element.py +++ b/holoviews/plotting/mpl/element.py @@ -424,6 +424,7 @@ def _set_axis_ticks(self, axis, ticks, log=False, rotation=0): tick.set_rotation(rotation) + @mpl_rc_context def update_frame(self, key, ranges=None, element=None): """ Set the plot(s) to the given frame number. Operates by @@ -838,6 +839,7 @@ def initialize_plot(self, ranges=None): title=self._format_title(key)) + @mpl_rc_context def update_frame(self, key, ranges=None, element=None): axis = self.handles['axis'] if element is None: diff --git a/holoviews/plotting/mpl/pandas.py b/holoviews/plotting/mpl/pandas.py index 21f7947a35..4ab96e7ef2 100644 --- a/holoviews/plotting/mpl/pandas.py +++ b/holoviews/plotting/mpl/pandas.py @@ -8,6 +8,7 @@ from ...core.options import Store from ...interface.pandas import DFrame, DataFrameView, pd from .element import ElementPlot +from .plot import mpl_rc_context class DFrameViewPlot(ElementPlot): @@ -65,7 +66,7 @@ def __init__(self, view, **params): if self.hmap.last.plot_type and 'plot_type' not in params: self.plot_type = self.hmap.last.plot_type - + @mpl_rc_context def initialize_plot(self, ranges=None): element = self.hmap.last self._validate(element) diff --git a/holoviews/plotting/mpl/plot.py b/holoviews/plotting/mpl/plot.py index 06d65bfa13..333b973874 100644 --- a/holoviews/plotting/mpl/plot.py +++ b/holoviews/plotting/mpl/plot.py @@ -1,6 +1,7 @@ from __future__ import division from itertools import chain +from contextlib import contextmanager import numpy as np import matplotlib as mpl @@ -19,12 +20,27 @@ from .util import compute_ratios, fix_aspect +@contextmanager +def _rc_context(rcparams): + """ + Context manager that temporarily overrides the pyplot rcParams. + """ + old_rcparams = plt.rcParams.copy() + plt.rcParams.update(rcparams) + try: + yield + except: + pass + finally: + plt.rcParams = old_rcparams + def mpl_rc_context(f): """ - Applies matplotlib rc params while when method is called. + Decorator for MPLPlot methods applying the matplotlib rc params + in the plots fig_rcparams while when method is called. """ def wrapper(self, *args, **kwargs): - with mpl.rc_context(rc=self.fig_rcparams): + with _rc_context(self.fig_rcparams): return f(self, *args, **kwargs) return wrapper diff --git a/holoviews/plotting/mpl/raster.py b/holoviews/plotting/mpl/raster.py index 9f840b84d9..7b22b78284 100644 --- a/holoviews/plotting/mpl/raster.py +++ b/holoviews/plotting/mpl/raster.py @@ -365,7 +365,7 @@ def initialize_plot(self, ranges=None): kwargs = self._get_axis_kwargs() return self._finalize_axis(key, ranges=ranges, **kwargs) - + @mpl_rc_context def update_frame(self, key, ranges=None): grid = self._get_frame(key) ranges = self.compute_ranges(self.layout, key, ranges)