This commit is contained in:
Lucas Verney 2016-03-09 14:58:53 +01:00
parent af29496245
commit 3ec424081f
2 changed files with 816 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -110,6 +110,9 @@ class Figure():
self.grid = grid self.grid = grid
self.savepath = savepath self.savepath = savepath
self.custom_mpl_rc = None self.custom_mpl_rc = None
# Working attributes
self.figure = None
self.axes = None
def __enter__(self): def __enter__(self):
return self return self
@ -443,7 +446,10 @@ class Figure():
if _DEFAULT_GROUP not in axes: if _DEFAULT_GROUP not in axes:
# Set the default group axis to None if it is not in the grid # Set the default group axis to None if it is not in the grid
axes[_DEFAULT_GROUP] = None axes[_DEFAULT_GROUP] = None
return figure, axes
# Set attributes
self.figure = figure
self.axes = axes
def _set_axes_properties(self, axis, group_): def _set_axes_properties(self, axis, group_):
# Set xlabel # Set xlabel
@ -524,19 +530,19 @@ class Figure():
:returns: A :mod:`matplotlib` figure. :returns: A :mod:`matplotlib` figure.
""" """
figure = None
# Use custom matplotlib context # Use custom matplotlib context
with mpl_custom_rc_context(rc=self.custom_mpl_rc): with mpl_custom_rc_context(rc=self.custom_mpl_rc):
# Create figure if self.figure is None or self.axes is None:
figure, axes = self._grid() # Create figure if necessary
self._grid()
# Add plots # Add plots
for group_ in self.plots: for group_ in self.plots:
# Get the axis corresponding to current group # Get the axis corresponding to current group
try: try:
axis = axes[group_] axis = self.axes[group_]
except KeyError: except KeyError:
# If not found, plot in the default group # If not found, plot in the default group
axis = axes[_DEFAULT_GROUP] axis = self.axes[_DEFAULT_GROUP]
# Skip this plot if the axis is None # Skip this plot if the axis is None
if axis is None: if axis is None:
continue continue
@ -556,7 +562,7 @@ class Figure():
tmp_plot.set_clip_on(False) tmp_plot.set_clip_on(False)
# Set ax properties # Set ax properties
self._set_axes_properties(axis, group_) self._set_axes_properties(axis, group_)
return figure return self.figure
def plot(data, **kwargs): def plot(data, **kwargs):