171
171
Parameters
172
172
----------
173
173
%(extra)s**kwargs
174
- Passed to `CartesianAxes`. You can optionally omit the {x}
175
- from `CartesianAxes.format` keywords beginning with ``{x}``.
176
- For example: ``ax.alt{x}(lim=(0, 10))`` is equivalent
177
- to ``ax.alt{x}({x}lim=(0, 10))``.
174
+ Passed to `CartesianAxes`. Supports all valid `~CartesianAxes.format` keywords.
175
+ You can optionally omit the {x} from keywords beginning with ``{x}`` -- for
176
+ example ``ax.alt{x}(lim=(0, 10))`` is equivalent to ``ax.alt{x}({x}lim=(0, 10))``.
177
+ You can also change the default side for the axis spine, axis tick marks, axis
178
+ tick labels, and/or axis labels by passing ``loc`` keywords. For example,
179
+ ``ax.alt{x}(loc='{x1}')`` changes the default side from {x2} to {x1}.
178
180
179
181
Returns
180
182
-------
@@ -1003,17 +1005,16 @@ def format(
1003
1005
self .set_aspect (aspect )
1004
1006
super ().format (rc_kw = rc_kw , rc_mode = rc_mode , ** kwargs )
1005
1007
1006
- def _parse_alt (self , kwargs , x ):
1008
+ def _parse_alt (self , x , ** kwargs ):
1007
1009
"""
1008
1010
Optionally omit the leading x or y from "twin axes" methods.
1009
1011
"""
1010
- keys = tuple (
1011
- key [1 :] for key in self ._format_signature .parameters if key [0 ] == x
1012
- )
1013
- kw = {
1014
- (x + key if key in keys else key ): val for key , val in kwargs .items ()
1015
- }
1016
- return kw
1012
+ keys = tuple (k [1 :] for k in self ._format_signature .parameters if k [0 ] == x )
1013
+ kwargs = {(x + k if k in keys else k ): v for k , v in kwargs .items ()}
1014
+ for axis in 'xy' : # standardize format() location aliases
1015
+ if axis + 'spineloc' in kwargs :
1016
+ kwargs [axis + 'loc' ] = kwargs .pop (axis + 'spineloc' )
1017
+ return kwargs
1017
1018
1018
1019
@docstring ._snippet_manager
1019
1020
def altx (self , ** kwargs ):
@@ -1028,32 +1029,24 @@ def altx(self, **kwargs):
1028
1029
# To restore matplotlib behavior, which draws "child" artists on top simply
1029
1030
# because the axes was created after the "parent" one, use the inset_axes
1030
1031
# zorder of 4 and make the background transparent.
1031
- kwargs = self ._parse_alt (kwargs , 'x' )
1032
+ kwargs = self ._parse_alt ('x' , ** kwargs )
1033
+ kwargs .setdefault ('xloc' , 'right' ) # other locations follow by default
1034
+ kwargs .setdefault ('grid' , False ) # note xgrid=True would override this
1035
+ kwargs .setdefault ('zorder' , 4 )
1036
+ kwargs .setdefault ('autoscaley_on' , self .get_autoscaley_on ())
1037
+
1038
+ # Initialize twin axes
1032
1039
ax = self ._make_twin_axes (
1033
1040
sharey = self , number = False , autoshare = False , projection = 'cartesian' , ** kwargs
1034
1041
)
1035
-
1036
- # Child defaults
1037
- # NOTE: This is not completely ideal since e.g. users passing labelloc
1038
- # will get overwritten. But mostly not a huge deal.
1039
1042
ax ._altx_parent = self
1040
- for side , spine in ax .spines .items ():
1041
- spine .set_visible (side == 'top' )
1042
- ax .xaxis .tick_top ()
1043
- ax .xaxis .set_label_position ('top' )
1044
- ax .yaxis .set_visible (False )
1045
1043
ax .patch .set_visible (False )
1046
- ax .grid (False )
1047
- ax .set_zorder (4 )
1048
- ax .set_autoscaley_on (self .get_autoscaley_on ())
1044
+ ax .yaxis .set_visible (False )
1049
1045
1050
1046
# Parent defaults
1051
- self .spines ['top' ].set_visible (False )
1052
- self .spines ['bottom' ].set_visible (True )
1053
- self .xaxis .tick_bottom ()
1054
- self .xaxis .set_label_position ('bottom' )
1055
-
1056
- # Add axes
1047
+ reverse = {'bottom' : 'top' , 'top' : 'bottom' }
1048
+ kwformat = {'xloc' : reverse .get (kwargs ['xloc' ], None )}
1049
+ self .format (** kwformat )
1057
1050
self .add_child_axes (ax ) # to facilitate tight layout
1058
1051
self .figure ._axstack .remove (ax ) # or gets drawn twice!
1059
1052
@@ -1064,31 +1057,25 @@ def alty(self, **kwargs):
1064
1057
"""
1065
1058
%(axes.alty)s
1066
1059
"""
1067
- # Initialize axes
1068
- kwargs = self ._parse_alt (kwargs , 'y' )
1060
+ # Parse input args
1061
+ kwargs = self ._parse_alt ('y' , ** kwargs )
1062
+ kwargs .setdefault ('yloc' , 'right' ) # other locations follow by default
1063
+ kwargs .setdefault ('grid' , False ) # note ygrid=True would override this
1064
+ kwargs .setdefault ('zorder' , 4 )
1065
+ kwargs .setdefault ('autoscalex_on' , self .get_autoscalex_on ())
1066
+
1067
+ # Initialize twin axes
1069
1068
ax = self ._make_twin_axes (
1070
1069
sharex = self , number = False , autoshare = False , projection = 'cartesian' , ** kwargs
1071
1070
)
1072
-
1073
- # Child defaults
1074
1071
ax ._alty_parent = self
1075
- for side , spine in ax .spines .items ():
1076
- spine .set_visible (side == 'right' )
1077
- ax .yaxis .tick_right ()
1078
- ax .yaxis .set_label_position ('right' )
1079
- ax .xaxis .set_visible (False )
1080
1072
ax .patch .set_visible (False )
1081
- ax .grid (False )
1082
- ax .set_zorder (4 )
1083
- ax .set_autoscalex_on (self .get_autoscalex_on ())
1084
-
1085
- # Parent defaults
1086
- self .spines ['right' ].set_visible (False )
1087
- self .spines ['left' ].set_visible (True )
1088
- self .yaxis .tick_left ()
1089
- self .yaxis .set_label_position ('left' )
1073
+ ax .xaxis .set_visible (False )
1090
1074
1091
- # Add axes
1075
+ # Update parent axes
1076
+ reverse = {'left' : 'right' , 'right' : 'left' }
1077
+ kwformat = {'yloc' : reverse .get (kwargs ['yloc' ], None )}
1078
+ self .format (** kwformat )
1092
1079
self .add_child_axes (ax ) # to facilitate tight layout
1093
1080
self .figure ._axstack .remove (ax ) # or gets drawn twice!
1094
1081
0 commit comments