Skip to content

Commit

Permalink
Merge pull request #1128 from ioam/mpl_rc_params
Browse files Browse the repository at this point in the history
Correctly set mpl rcparams on Layouts and Grids
  • Loading branch information
jlstevens authored Feb 12, 2017
2 parents 173b049 + 18e4831 commit 903e8ef
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def __init__(self, fig=None, axis=None, **params):
for i in self.fig_inches]
else:
self.fig_inches *= self.fig_scale
fig, axis = self._init_axis(fig, axis)
rc_params = self.fig_rcparams
if self.fig_latex:
self.fig_rcparams['text.usetex'] = True

with mpl.rc_context(rc=self.fig_rcparams):
fig, axis = self._init_axis(fig, axis)

self.handles['fig'] = fig
self.handles['axis'] = axis

Expand All @@ -122,27 +128,22 @@ def _init_axis(self, fig, axis):
a new figure.
"""
if not fig and self._create_fig:
rc_params = self.fig_rcparams
if self.fig_latex:
rc_params['text.usetex'] = True
with mpl.rc_context(rc=rc_params):
fig = plt.figure()
l, b, r, t = self.fig_bounds
inches = self.fig_inches
fig.subplots_adjust(left=l, bottom=b, right=r, top=t)
fig.patch.set_alpha(self.fig_alpha)
if isinstance(inches, (tuple, list)):
inches = list(inches)
if inches[0] is None:
inches[0] = inches[1]
elif inches[1] is None:
inches[1] = inches[0]
fig.set_size_inches(list(inches))
else:
fig.set_size_inches([inches, inches])
axis = fig.add_subplot(111, projection=self.projection)
axis.set_aspect('auto')

fig = plt.figure()
l, b, r, t = self.fig_bounds
inches = self.fig_inches
fig.subplots_adjust(left=l, bottom=b, right=r, top=t)
fig.patch.set_alpha(self.fig_alpha)
if isinstance(inches, (tuple, list)):
inches = list(inches)
if inches[0] is None:
inches[0] = inches[1]
elif inches[1] is None:
inches[1] = inches[0]
fig.set_size_inches(list(inches))
else:
fig.set_size_inches([inches, inches])
axis = fig.add_subplot(111, projection=self.projection)
axis.set_aspect('auto')
return fig, axis


Expand Down Expand Up @@ -208,10 +209,6 @@ def anim(self, start=0, stop=None, fps=30):
return anim

def update(self, key):
rc_params = self.fig_rcparams
if self.fig_latex:
rc_params['text.usetex'] = True
mpl.rcParams.update(rc_params)
if len(self) == 1 and key == 0 and not self.drawn:
return self.initialize_plot()
return self.__getitem__(key)
Expand Down Expand Up @@ -297,7 +294,10 @@ def __init__(self, layout, axis=None, create_axes=True, ranges=None,
self.cols, self.rows = layout.shape
self.fig_inches = self._get_size()
self._layoutspec = gridspec.GridSpec(self.rows, self.cols, **grid_kwargs)
self.subplots, self.subaxes, self.layout = self._create_subplots(layout, axis, ranges, create_axes)

with mpl.rc_context(rc=self.fig_rcparams):
self.subplots, self.subaxes, self.layout = self._create_subplots(layout, axis,
ranges, create_axes)


def _get_size(self):
Expand Down Expand Up @@ -709,7 +709,8 @@ class LayoutPlot(GenericLayoutPlot, CompositePlot):

def __init__(self, layout, **params):
super(LayoutPlot, self).__init__(layout=layout, **params)
self.subplots, self.subaxes, self.layout = self._compute_gridspec(layout)
with mpl.rc_context(rc=self.fig_rcparams):
self.subplots, self.subaxes, self.layout = self._compute_gridspec(layout)


def _compute_gridspec(self, layout):
Expand Down

0 comments on commit 903e8ef

Please sign in to comment.