@@ -39,7 +39,8 @@ def __init__(self, fig, pos, horizontal, vertical,
3939 aspect : bool
4040 Whether overall rectangular area is reduced so that the relative
4141 part of the horizontal and vertical scales have the same scale.
42- anchor : {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W'}
42+ anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', \
43+ 'NW', 'W'}
4344 Placement of the reduced rectangle, when *aspect* is True.
4445 """
4546
@@ -48,6 +49,7 @@ def __init__(self, fig, pos, horizontal, vertical,
4849 self ._horizontal = horizontal
4950 self ._vertical = vertical
5051 self ._anchor = anchor
52+ self .set_anchor (anchor )
5153 self ._aspect = aspect
5254 self ._xrefindex = 0
5355 self ._yrefindex = 0
@@ -106,7 +108,8 @@ def set_anchor(self, anchor):
106108 """
107109 Parameters
108110 ----------
109- anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
111+ anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', \
112+ 'NW', 'W'}
110113 Either an (*x*, *y*) pair of relative coordinates (0 is left or
111114 bottom, 1 is right or top), 'C' (center), or a cardinal direction
112115 ('SW', southwest, is bottom left, etc.).
@@ -115,8 +118,10 @@ def set_anchor(self, anchor):
115118 --------
116119 .Axes.set_anchor
117120 """
118- if len (anchor ) != 2 :
121+ if isinstance (anchor , str ) :
119122 _api .check_in_list (mtransforms .Bbox .coefs , anchor = anchor )
123+ elif not isinstance (anchor , (tuple , list )) or len (anchor ) != 2 :
124+ raise TypeError ("anchor must be str or 2-tuple" )
120125 self ._anchor = anchor
121126
122127 def get_anchor (self ):
@@ -250,6 +255,8 @@ def new_locator(self, nx, ny, nx1=None, ny1=None):
250255 ny1 if ny1 is not None else ny + 1 )
251256
252257 def append_size (self , position , size ):
258+ _api .check_in_list (["left" , "right" , "bottom" , "top" ],
259+ position = position )
253260 if position == "left" :
254261 self ._horizontal .insert (0 , size )
255262 self ._xrefindex += 1
@@ -258,11 +265,8 @@ def append_size(self, position, size):
258265 elif position == "bottom" :
259266 self ._vertical .insert (0 , size )
260267 self ._yrefindex += 1
261- elif position == " top" :
268+ else : # ' top'
262269 self ._vertical .append (size )
263- else :
264- _api .check_in_list (["left" , "right" , "bottom" , "top" ],
265- position = position )
266270
267271 def add_auto_adjustable_area (self , use_axes , pad = 0.1 , adjust_dirs = None ):
268272 """
@@ -512,21 +516,14 @@ def append_axes(self, position, size, pad=None, add_to_figure=True, *,
512516 **kwargs
513517 All extra keywords arguments are passed to the created axes.
514518 """
515- if position == "left" :
516- ax = self .new_horizontal (
517- size , pad , pack_start = True , axes_class = axes_class , ** kwargs )
518- elif position == "right" :
519- ax = self .new_horizontal (
520- size , pad , pack_start = False , axes_class = axes_class , ** kwargs )
521- elif position == "bottom" :
522- ax = self .new_vertical (
523- size , pad , pack_start = True , axes_class = axes_class , ** kwargs )
524- elif position == "top" :
525- ax = self .new_vertical (
526- size , pad , pack_start = False , axes_class = axes_class , ** kwargs )
527- else :
528- _api .check_in_list (["left" , "right" , "bottom" , "top" ],
529- position = position )
519+ create_axes , pack_start = _api .check_getitem ({
520+ "left" : (self .new_horizontal , True ),
521+ "right" : (self .new_horizontal , False ),
522+ "bottom" : (self .new_vertical , True ),
523+ "top" : (self .new_vertical , False ),
524+ }, position = position )
525+ ax = create_axes (
526+ size , pad , pack_start = pack_start , axes_class = axes_class , ** kwargs )
530527 if add_to_figure :
531528 self ._fig .add_axes (ax )
532529 return ax
0 commit comments