From ccd634271ba8afa2ae140e8f383d737323d7f482 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 9 May 2021 15:28:39 +0200 Subject: [PATCH] Small simplifications to FloatingAxesBase. - _axes_class_floating is just the `super(FloatingAxesBase, self)` class (per its definition in floatingaxes_class_factory), so we can just use super-calls instead of explicitly referring to it (both in `__init__` and in `cla`); and then we can just delete _axes_class_floating. - Combine _gen_axes_patch into a single line (it's not as if the intermediary variable names were particularly helpful). - In cla(), the super() axes patch is already not in the draw tree (it's FloatingAxesBase._gen_axes_patch() which is there, so no need to adjust its visibility). _original_patch is never used anywhere, so delete it. --- lib/mpl_toolkits/axisartist/floating_axes.py | 31 +++++++------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index e1958939c7d5..01f8322de7e8 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -318,32 +318,24 @@ def __init__(self, *args, **kwargs): raise ValueError("FloatingAxes requires grid_helper argument") if not hasattr(grid_helper, "get_boundary"): raise ValueError("grid_helper must implement get_boundary method") - - self._axes_class_floating.__init__(self, *args, **kwargs) - + super().__init__(*args, **kwargs) self.set_aspect(1.) self.adjust_axes_lim() def _gen_axes_patch(self): # docstring inherited - grid_helper = self.get_grid_helper() - t = grid_helper.get_boundary() - return mpatches.Polygon(t) + return mpatches.Polygon(self.get_grid_helper().get_boundary()) def cla(self): - self._axes_class_floating.cla(self) - # HostAxes.cla(self) + super().cla() self.patch.set_transform(self.transData) - - patch = self._axes_class_floating._gen_axes_patch(self) - patch.set_figure(self.figure) - patch.set_visible(False) - patch.set_transform(self.transAxes) - - self.patch.set_clip_path(patch) - self.gridlines.set_clip_path(patch) - - self._original_patch = patch + # The original patch is not in the draw tree; it is only used for + # clipping purposes. + orig_patch = super()._gen_axes_patch() + orig_patch.set_figure(self.figure) + orig_patch.set_transform(self.transAxes) + self.patch.set_clip_path(orig_patch) + self.gridlines.set_clip_path(orig_patch) def adjust_axes_lim(self): grid_helper = self.get_grid_helper() @@ -363,8 +355,7 @@ def adjust_axes_lim(self): @functools.lru_cache(None) def floatingaxes_class_factory(axes_class): return type("Floating %s" % axes_class.__name__, - (FloatingAxesBase, axes_class), - {'_axes_class_floating': axes_class}) + (FloatingAxesBase, axes_class), {}) FloatingAxes = floatingaxes_class_factory(