From ff30a3b871903291047729de0f836a7ad0a6c2b9 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 9 Feb 2019 20:32:43 +0100 Subject: [PATCH] Deduplicate some code between floating_axes and grid_helper_curvelinear. `floating_axes.GridHelperCurveLinear` inherits from `grid_helper_curvelinear.GridHelperCurveLinear`. - In the constructor, remove the duplicated docstring and the init of `self._old_values` (also in the base class). - Remove commented out `update_grid_finder` and `_update`, which are directly inherited from the base class anyways. - The `new_fixed_axis` implementation looks the same in both classes, except that 1) they refer to different FixedAxisArtistHelper classes (add a comment to clarify) and 2) one of them sets clipping and not the other (likely a bug; leave a comment suggesting to investigate). - Remove commented-out setting of `grid_info` in _update_grid (grid_info is being redefined below anyways). - Remove commented-out setting of `_grid_params` in base class (that attribute doesn't exist anywhere else in the codebase). --- lib/mpl_toolkits/axisartist/floating_axes.py | 45 +++---------------- .../axisartist/grid_helper_curvelinear.py | 23 ++-------- 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index 91f51d7fb79a..5dc3dbb6e339 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -205,21 +205,9 @@ def __init__(self, aux_trans, extremes, grid_locator2=None, tick_formatter1=None, tick_formatter2=None): - """ - aux_trans : a transform from the source (curved) coordinate to - target (rectilinear) coordinate. An instance of MPL's Transform - (inverse transform should be defined) or a tuple of two callable - objects which defines the transform and its inverse. The callables - need take two arguments of array of source coordinates and - should return two target coordinates: - e.g., *x2, y2 = trans(x1, y1)* - """ - - self._old_values = None - + # docstring inherited self._extremes = extremes extreme_finder = ExtremeFinderFixed(extremes) - super().__init__(aux_trans, extreme_finder, grid_locator1=grid_locator1, @@ -227,21 +215,6 @@ def __init__(self, aux_trans, extremes, tick_formatter1=tick_formatter1, tick_formatter2=tick_formatter2) - # def update_grid_finder(self, aux_trans=None, **kw): - # if aux_trans is not None: - # self.grid_finder.update_transform(aux_trans) - # self.grid_finder.update(**kw) - # self.invalidate() - - # def _update(self, x1, x2, y1, y2): - # "bbox in 0-based image coordinates" - # # update wcsgrid - # if self.valid() and self._old_values == (x1, x2, y1, y2): - # return - # self._update_grid(x1, y1, x2, y2) - # self._old_values = (x1, x2, y1, y2) - # self._force_update = False - def get_data_boundary(self, side): """ return v= 0 , nth=1 @@ -257,20 +230,18 @@ def new_fixed_axis(self, loc, axis_direction=None, offset=None, axes=None): - if axes is None: axes = self.axes - if axis_direction is None: axis_direction = loc - - _helper = FixedAxisArtistHelper(self, loc, - nth_coord_ticks=nth_coord) - + # This is not the same as the FixedAxisArtistHelper class used by + # grid_helper_curvelinear.GridHelperCurveLinear.new_fixed_axis! + _helper = FixedAxisArtistHelper( + self, loc, nth_coord_ticks=nth_coord) axisline = AxisArtist(axes, _helper, axis_direction=axis_direction) + # Perhaps should be moved to the base class? axisline.line.set_clip_on(True) axisline.line.set_clip_box(axisline.axes.bbox) - return axisline # new_floating_axis will inherit the grid_helper's extremes. @@ -295,9 +266,6 @@ def new_fixed_axis(self, loc, # return axis def _update_grid(self, x1, y1, x2, y2): - - # self.grid_info = self.grid_finder.get_grid_info(x1, y1, x2, y2) - if self.grid_info is None: self.grid_info = dict() @@ -361,7 +329,6 @@ def get_gridlines(self, which="major", axis="both"): if axis in ["both", "y"]: for gl in self.grid_info["lat_lines"]: grid_lines.extend([gl]) - return grid_lines def get_boundary(self): diff --git a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py index 52eb907f2bfd..9427d92c712f 100644 --- a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py +++ b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py @@ -311,12 +311,9 @@ def __init__(self, aux_trans, e.g., ``x2, y2 = trans(x1, y1)`` """ super().__init__() - self.grid_info = None self._old_values = None - # self._grid_params = dict() self._aux_trans = aux_trans - self.grid_finder = GridFinder(aux_trans, extreme_finder, grid_locator1, @@ -325,24 +322,18 @@ def __init__(self, aux_trans, tick_formatter2) def update_grid_finder(self, aux_trans=None, **kw): - if aux_trans is not None: self.grid_finder.update_transform(aux_trans) - self.grid_finder.update(**kw) self.invalidate() def _update(self, x1, x2, y1, y2): "bbox in 0-based image coordinates" # update wcsgrid - if self.valid() and self._old_values == (x1, x2, y1, y2): return - self._update_grid(x1, y1, x2, y2) - self._old_values = (x1, x2, y1, y2) - self._force_update = False def new_fixed_axis(self, loc, @@ -350,19 +341,15 @@ def new_fixed_axis(self, loc, axis_direction=None, offset=None, axes=None): - if axes is None: axes = self.axes - if axis_direction is None: axis_direction = loc - _helper = FixedAxisArtistHelper(self, loc, - # nth_coord, - nth_coord_ticks=nth_coord, - ) - + _helper = FixedAxisArtistHelper( + self, loc, nth_coord_ticks=nth_coord) axisline = AxisArtist(axes, _helper, axis_direction=axis_direction) - + # Why is clip not set on axisline, unlike in new_floating_axis or in + # the floating_axig.GridHelperCurveLinear subclass? return axisline def new_floating_axis(self, nth_coord, @@ -401,14 +388,12 @@ def _update_grid(self, x1, y1, x2, y2): def get_gridlines(self, which="major", axis="both"): grid_lines = [] - if axis in ["both", "x"]: for gl in self.grid_info["lon"]["lines"]: grid_lines.extend(gl) if axis in ["both", "y"]: for gl in self.grid_info["lat"]["lines"]: grid_lines.extend(gl) - return grid_lines def get_tick_iterator(self, nth_coord, axis_side, minor=False):