Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce184f9

Browse files
authored
Merge pull request #13394 from anntzer/axisartist-dedup
Deduplicate some code between floating_axes and grid_helper_curvelinear.
2 parents f9e5303 + ff30a3b commit ce184f9

File tree

2 files changed

+10
-58
lines changed

2 files changed

+10
-58
lines changed

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -205,43 +205,16 @@ def __init__(self, aux_trans, extremes,
205205
grid_locator2=None,
206206
tick_formatter1=None,
207207
tick_formatter2=None):
208-
"""
209-
aux_trans : a transform from the source (curved) coordinate to
210-
target (rectilinear) coordinate. An instance of MPL's Transform
211-
(inverse transform should be defined) or a tuple of two callable
212-
objects which defines the transform and its inverse. The callables
213-
need take two arguments of array of source coordinates and
214-
should return two target coordinates:
215-
e.g., *x2, y2 = trans(x1, y1)*
216-
"""
217-
218-
self._old_values = None
219-
208+
# docstring inherited
220209
self._extremes = extremes
221210
extreme_finder = ExtremeFinderFixed(extremes)
222-
223211
super().__init__(aux_trans,
224212
extreme_finder,
225213
grid_locator1=grid_locator1,
226214
grid_locator2=grid_locator2,
227215
tick_formatter1=tick_formatter1,
228216
tick_formatter2=tick_formatter2)
229217

230-
# def update_grid_finder(self, aux_trans=None, **kw):
231-
# if aux_trans is not None:
232-
# self.grid_finder.update_transform(aux_trans)
233-
# self.grid_finder.update(**kw)
234-
# self.invalidate()
235-
236-
# def _update(self, x1, x2, y1, y2):
237-
# "bbox in 0-based image coordinates"
238-
# # update wcsgrid
239-
# if self.valid() and self._old_values == (x1, x2, y1, y2):
240-
# return
241-
# self._update_grid(x1, y1, x2, y2)
242-
# self._old_values = (x1, x2, y1, y2)
243-
# self._force_update = False
244-
245218
def get_data_boundary(self, side):
246219
"""
247220
return v= 0 , nth=1
@@ -257,20 +230,18 @@ def new_fixed_axis(self, loc,
257230
axis_direction=None,
258231
offset=None,
259232
axes=None):
260-
261233
if axes is None:
262234
axes = self.axes
263-
264235
if axis_direction is None:
265236
axis_direction = loc
266-
267-
_helper = FixedAxisArtistHelper(self, loc,
268-
nth_coord_ticks=nth_coord)
269-
237+
# This is not the same as the FixedAxisArtistHelper class used by
238+
# grid_helper_curvelinear.GridHelperCurveLinear.new_fixed_axis!
239+
_helper = FixedAxisArtistHelper(
240+
self, loc, nth_coord_ticks=nth_coord)
270241
axisline = AxisArtist(axes, _helper, axis_direction=axis_direction)
242+
# Perhaps should be moved to the base class?
271243
axisline.line.set_clip_on(True)
272244
axisline.line.set_clip_box(axisline.axes.bbox)
273-
274245
return axisline
275246

276247
# new_floating_axis will inherit the grid_helper's extremes.
@@ -295,9 +266,6 @@ def new_fixed_axis(self, loc,
295266
# return axis
296267

297268
def _update_grid(self, x1, y1, x2, y2):
298-
299-
# self.grid_info = self.grid_finder.get_grid_info(x1, y1, x2, y2)
300-
301269
if self.grid_info is None:
302270
self.grid_info = dict()
303271

@@ -361,7 +329,6 @@ def get_gridlines(self, which="major", axis="both"):
361329
if axis in ["both", "y"]:
362330
for gl in self.grid_info["lat_lines"]:
363331
grid_lines.extend([gl])
364-
365332
return grid_lines
366333

367334
def get_boundary(self):

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,9 @@ def __init__(self, aux_trans,
311311
e.g., ``x2, y2 = trans(x1, y1)``
312312
"""
313313
super().__init__()
314-
315314
self.grid_info = None
316315
self._old_values = None
317-
# self._grid_params = dict()
318316
self._aux_trans = aux_trans
319-
320317
self.grid_finder = GridFinder(aux_trans,
321318
extreme_finder,
322319
grid_locator1,
@@ -325,44 +322,34 @@ def __init__(self, aux_trans,
325322
tick_formatter2)
326323

327324
def update_grid_finder(self, aux_trans=None, **kw):
328-
329325
if aux_trans is not None:
330326
self.grid_finder.update_transform(aux_trans)
331-
332327
self.grid_finder.update(**kw)
333328
self.invalidate()
334329

335330
def _update(self, x1, x2, y1, y2):
336331
"bbox in 0-based image coordinates"
337332
# update wcsgrid
338-
339333
if self.valid() and self._old_values == (x1, x2, y1, y2):
340334
return
341-
342335
self._update_grid(x1, y1, x2, y2)
343-
344336
self._old_values = (x1, x2, y1, y2)
345-
346337
self._force_update = False
347338

348339
def new_fixed_axis(self, loc,
349340
nth_coord=None,
350341
axis_direction=None,
351342
offset=None,
352343
axes=None):
353-
354344
if axes is None:
355345
axes = self.axes
356-
357346
if axis_direction is None:
358347
axis_direction = loc
359-
_helper = FixedAxisArtistHelper(self, loc,
360-
# nth_coord,
361-
nth_coord_ticks=nth_coord,
362-
)
363-
348+
_helper = FixedAxisArtistHelper(
349+
self, loc, nth_coord_ticks=nth_coord)
364350
axisline = AxisArtist(axes, _helper, axis_direction=axis_direction)
365-
351+
# Why is clip not set on axisline, unlike in new_floating_axis or in
352+
# the floating_axig.GridHelperCurveLinear subclass?
366353
return axisline
367354

368355
def new_floating_axis(self, nth_coord,
@@ -401,14 +388,12 @@ def _update_grid(self, x1, y1, x2, y2):
401388

402389
def get_gridlines(self, which="major", axis="both"):
403390
grid_lines = []
404-
405391
if axis in ["both", "x"]:
406392
for gl in self.grid_info["lon"]["lines"]:
407393
grid_lines.extend(gl)
408394
if axis in ["both", "y"]:
409395
for gl in self.grid_info["lat"]["lines"]:
410396
grid_lines.extend(gl)
411-
412397
return grid_lines
413398

414399
def get_tick_iterator(self, nth_coord, axis_side, minor=False):

0 commit comments

Comments
 (0)