@@ -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 ):
@@ -511,20 +516,14 @@ def append_axes(self, position, size, pad=None, add_to_figure=True, *,
511516 **kwargs
512517 All extra keywords arguments are passed to the created axes.
513518 """
514- _api .check_in_list (["left" , "right" , "bottom" , "top" ],
515- position = position )
516- if position == "left" :
517- ax = self .new_horizontal (
518- size , pad , pack_start = True , axes_class = axes_class , ** kwargs )
519- elif position == "right" :
520- ax = self .new_horizontal (
521- size , pad , pack_start = False , axes_class = axes_class , ** kwargs )
522- elif position == "bottom" :
523- ax = self .new_vertical (
524- size , pad , pack_start = True , axes_class = axes_class , ** kwargs )
525- else : # "top"
526- ax = self .new_vertical (
527- size , pad , pack_start = False , axes_class = axes_class , ** kwargs )
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 )
528527 if add_to_figure :
529528 self ._fig .add_axes (ax )
530529 return ax
0 commit comments