@@ -290,37 +290,21 @@ def get_size(self, renderer):
290290
291291
292292class GetExtentHelper (object ):
293- def _get_left (self , axes_bbox ):
294- return axes_bbox .xmin - self .xmin
295-
296- def _get_right (self , axes_bbox ):
297- return self .xmax - axes_bbox .xmax
298-
299- def _get_bottom (self , axes_bbox ):
300- return axes_bbox .ymin - self .ymin
301-
302- def _get_top (self , axes_bbox ):
303- return self .ymax - axes_bbox .ymax
304-
305- _get_func_map = dict (left = _get_left ,
306- right = _get_right ,
307- bottom = _get_bottom ,
308- top = _get_top )
309-
310- del _get_left , _get_right , _get_bottom , _get_top
293+ _get_func_map = {
294+ "left" : lambda self , axes_bbox : axes_bbox .xmin - self .xmin ,
295+ "right" : lambda self , axes_bbox : self .xmax - axes_bbox .xmax ,
296+ "bottom" : lambda self , axes_bbox : axes_bbox .ymin - self .ymin ,
297+ "top" : lambda self , axes_bbox : self .ymax - axes_bbox .ymax ,
298+ }
311299
312300 def __init__ (self , ax , direction ):
313- if isinstance (ax , Axes ):
314- self ._ax_list = [ax ]
315- else :
316- self ._ax_list = ax
317-
318- try :
319- self ._get_func = self ._get_func_map [direction ]
320- except KeyError :
301+ if direction not in self ._get_func_map :
321302 raise KeyError ("direction must be one of left, right, bottom, top" )
303+ self ._ax_list = [ax ] if isinstance (ax , Axes ) else ax
304+ self ._direction = direction
322305
323306 def __call__ (self , renderer ):
324- vl = [self ._get_func (ax .get_tightbbox (renderer , False ),
325- ax .bbox ) for ax in self ._ax_list ]
307+ get_func = self ._get_func_map [self ._direction ]
308+ vl = [get_func (ax .get_tightbbox (renderer , False ), ax .bbox )
309+ for ax in self ._ax_list ]
326310 return max (vl )
0 commit comments