From 46a853fdb9cf3231175dfab00fb1d6fbb2bb843b Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 10 Mar 2023 13:27:27 +0100 Subject: [PATCH] Store FloatingAxes "extremes" info in fewer places. Make the value returned by ExtremeFinderFixed be the canonical place to query the value of the extremes parameter. This may make it easier to change the extremes post-facto (there's fewer places to update). Also deprecate the related get_data_boundary method, which doesn't exist anywhere else and isn't really needed as a separate API: we can just inline it into its only call site instead. --- .../deprecations/25427-AL.rst | 4 ++++ lib/mpl_toolkits/axisartist/floating_axes.py | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/25427-AL.rst diff --git a/doc/api/next_api_changes/deprecations/25427-AL.rst b/doc/api/next_api_changes/deprecations/25427-AL.rst new file mode 100644 index 000000000000..1f1c886b3559 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/25427-AL.rst @@ -0,0 +1,4 @@ +``GridHelperCurveLinear.get_data_boundary`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... is deprecated. Use ``grid_finder.extreme_finder(*[None] * 5)`` to get the +extremes of the grid. diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index 4c62730a7b59..b0a832123b90 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -33,7 +33,10 @@ def __init__(self, grid_helper, side, nth_coord_ticks=None): nth_coord = along which coordinate value varies. nth_coord = 0 -> x axis, nth_coord = 1 -> y axis """ - value, nth_coord = grid_helper.get_data_boundary(side) + lon1, lon2, lat1, lat2 = grid_helper.grid_finder.extreme_finder(*[None] * 5) + value, nth_coord = _api.check_getitem( + dict(left=(lon1, 0), right=(lon2, 0), bottom=(lat1, 1), top=(lat2, 1)), + side=side) super().__init__(grid_helper, nth_coord, value, axis_direction=side) if nth_coord_ticks is None: nth_coord_ticks = nth_coord @@ -58,7 +61,7 @@ def get_tick_iterators(self, axes): lon_levs, lon_n, lon_factor = self._grid_info["lon_info"] xx0 = lon_levs / lon_factor - extremes = self.grid_helper._extremes + extremes = self.grid_helper.grid_finder.extreme_finder(*[None] * 5) xmin, xmax = sorted(extremes[:2]) ymin, ymax = sorted(extremes[2:]) @@ -137,20 +140,19 @@ def __init__(self, aux_trans, extremes, tick_formatter1=None, tick_formatter2=None): # docstring inherited - self._extremes = extremes - extreme_finder = ExtremeFinderFixed(extremes) super().__init__(aux_trans, - extreme_finder, + extreme_finder=ExtremeFinderFixed(extremes), grid_locator1=grid_locator1, grid_locator2=grid_locator2, tick_formatter1=tick_formatter1, tick_formatter2=tick_formatter2) + @_api.deprecated("3.8") def get_data_boundary(self, side): """ Return v=0, nth=1. """ - lon1, lon2, lat1, lat2 = self._extremes + lon1, lon2, lat1, lat2 = self.grid_finder.extreme_finder(*[None] * 5) return dict(left=(lon1, 0), right=(lon2, 0), bottom=(lat1, 1), @@ -262,10 +264,7 @@ def __init__(self, *args, grid_helper, **kwargs): def _gen_axes_patch(self): # docstring inherited - # Using a public API to access _extremes. - (x0, _), (x1, _), (y0, _), (y1, _) = map( - self.get_grid_helper().get_data_boundary, - ["left", "right", "bottom", "top"]) + x0, x1, y0, y1 = self.get_grid_helper().grid_finder.extreme_finder(*[None] * 5) patch = mpatches.Polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)]) patch.get_path()._interpolation_steps = 100 return patch