8000 Deduplicate some code between floating_axes and grid_helper_curvelinear. by anntzer · Pull Request #13394 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deduplicate some code between floating_axes and grid_helper_curvelinear. #13394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 6 additions & 39 deletions lib/mpl_toolkits/axisartist/floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,43 +205,16 @@ 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,
grid_locator2=grid_locator2,
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
Expand All @@ -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.
Expand All @@ -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()

Expand Down Expand Up @@ -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):
Expand Down
23 changes: 4 additions & 19 deletions lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -325,44 +322,34 @@ 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,
nth_coord=None,
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,
Expand Down Expand Up @@ -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):
Expand Down
0