Skip to content

Commit 66cc32a

Browse files
committed
Define GridFinder.{,inv_}transform_xy as normal methods.
... rather than as dynamical attributes using local functions. This way they show up in the docs, and avoid making GridFinder unpicklable.
1 parent ae47ad2 commit 66cc32a

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/mpl_toolkits/axisartist/grid_finder.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,26 @@ def _clip_grid_lines_and_find_ticks(self, lines, values, levs, bb):
176176
return gi
177177

178178
def update_transform(self, aux_trans):
179-
if isinstance(aux_trans, Transform):
180-
def transform_xy(x, y):
181-
ll1 = np.column_stack([x, y])
182-
ll2 = aux_trans.transform(ll1)
183-
lon, lat = ll2[:, 0], ll2[:, 1]
184-
return lon, lat
185-
186-
def inv_transform_xy(x, y):
187-
ll1 = np.column_stack([x, y])
188-
ll2 = aux_trans.inverted().transform(ll1)
189-
lon, lat = ll2[:, 0], ll2[:, 1]
190-
return lon, lat
191-
179+
if not isinstance(aux_trans, Transform) and len(aux_trans) != 2:
180+
raise TypeError("'aux_trans' must be either a Transform instance "
181+
"or a pair of callables")
182+
self._aux_transform = aux_trans
183+
184+
def transform_xy(self, x, y):
185+
aux_trf = self._aux_transform
186+
if isinstance(aux_trf, Transform):
187+
return aux_trf.transform(np.column_stack([x, y])).T
192188
else:
193-
transform_xy, inv_transform_xy = aux_trans
189+
transform_xy, inv_transform_xy = aux_trf
190+
return transform_xy(x, y)
194191

195-
self.transform_xy = transform_xy
196-
self.inv_transform_xy = inv_transform_xy
192+
def inv_transform_xy(self, x, y):
193+
aux_trf = self._aux_transform
194+
if isinstance(aux_trf, Transform):
195+
return aux_trf.inverted().transform(np.column_stack([x, y])).T
196+
else:
197+
transform_xy, inv_transform_xy = aux_trf
198+
return inv_transform_xy(x, y)
197199

198200
def update(self, **kw):
199201
for k in kw:

0 commit comments

Comments
 (0)