@@ -119,30 +119,18 @@ def _parse_format(mode=2, rc_kw=None, **kwargs):
119119class Axes (maxes .Axes ):
120120 """Lowest-level axes subclass. Handles titles and axis
121121 sharing. Adds several new methods and overrides existing ones."""
122-
123- def __init__ (self , * args , number = None ,
124- sharex = 0 , sharey = 0 ,
125- spanx = None , spany = None , alignx = None , aligny = None ,
126- main = False ,
127- ** kwargs ):
122+ def __init__ (self , * args , number = None , main = False , ** kwargs ):
128123 """
129124 Parameters
130125 ----------
131126 number : int
132- The subplot number, used for a-b-c labelling (see
133- `~Axes.format`).
134- sharex, sharey : {3, 2, 1, 0}, optional
135- The "axis sharing level" for the *x* axis, *y* axis, or both
136- axes. See `~proplot.subplots.subplots` for details.
137- spanx, spany : bool, optional
138- Boolean toggle for whether spanning labels are enabled for the
139- *x* and *y* axes. See `~proplot.subplots.subplots` for details.
140- alignx, aligny : bool, optional
141- Boolean toggle for whether aligned axis labels are enabled for the
142- *x* and *y* axes. See `~proplot.subplots.subplots` for details.
127+ The subplot number, used for a-b-c labeling. See `~Axes.format`
128+ for details. Note the first axes is ``1``, not ``0``.
143129 main : bool, optional
144130 Used internally, indicates whether this is a "main axes" rather
145131 than a twin, panel, or inset axes.
132+ *args, **kwargs
133+ Passed to `~matplotlib.axes.Axes`.
146134
147135 See also
148136 --------
@@ -155,7 +143,6 @@ def __init__(self, *args, number=None,
155143 # Ensure isDefault_minloc enabled at start, needed for dual axes
156144 self .xaxis .isDefault_minloc = self .yaxis .isDefault_minloc = True
157145 # Properties
158- self .number = number
159146 self ._abc_loc = None
160147 self ._abc_text = None
161148 self ._titles_dict = {} # dictionary of titles and locs
@@ -180,8 +167,6 @@ def __init__(self, *args, number=None,
180167 self ._altx_parent = None
181168 self ._auto_colorbar = {} # stores handles and kwargs for auto colorbar
182169 self ._auto_legend = {}
183- # Text labels
184- # TODO: Add text labels as panels instead of as axes children?
185170 coltransform = mtransforms .blended_transform_factory (
186171 self .transAxes , self .figure .transFigure )
187172 rowtransform = mtransforms .blended_transform_factory (
@@ -194,15 +179,10 @@ def __init__(self, *args, number=None,
194179 0.5 , 0.05 , '' , va = 'top' , ha = 'center' , transform = coltransform )
195180 self ._tlabel = self .text (
196181 0.5 , 0.95 , '' , va = 'bottom' , ha = 'center' , transform = coltransform )
197- # Shared and spanning axes
182+ self ._share_setup ()
183+ self .number = number # for abc numbering
198184 if main :
199185 self .figure ._axes_main .append (self )
200- self ._spanx_on = spanx
201- self ._spany_on = spany
202- self ._alignx_on = alignx
203- self ._aligny_on = aligny
204- self ._sharex_level = sharex
205- self ._sharey_level = sharey
206186 self .format (mode = 1 ) # mode == 1 applies the rcShortParams
207187
208188 def _draw_auto_legends_colorbars (self ):
@@ -360,7 +340,7 @@ def _loc_translate(loc, default=None):
360340 return loc
361341
362342 def _make_inset_locator (self , bounds , trans ):
363- """Helper function, copied from private matplotlib version ."""
343+ """Return a locator that determines inset axes bounds ."""
364344 def inset_locator (ax , renderer ):
365345 bbox = mtransforms .Bbox .from_bounds (* bounds )
366346 bb = mtransforms .TransformedBbox (bbox , trans )
@@ -370,22 +350,22 @@ def inset_locator(ax, renderer):
370350 return inset_locator
371351
372352 def _range_gridspec (self , x ):
373- """Gets the column or row range for the axes."""
374- subplotspec = self .get_subplotspec ()
353+ """Return the column or row gridspec range for the axes."""
354+ if not hasattr (self , 'get_subplotspec' ):
355+ raise RuntimeError (f'Axes is not a subplot.' )
356+ ss = self .get_subplotspec ()
375357 if x == 'x' :
376- _ , _ , _ , _ , col1 , col2 = subplotspec . get_active_rows_columns ()
358+ _ , _ , _ , _ , col1 , col2 = ss . get_rows_columns ()
377359 return col1 , col2
378360 else :
379- _ , _ , row1 , row2 , _ , _ = subplotspec . get_active_rows_columns ()
361+ _ , _ , row1 , row2 , _ , _ = ss . get_rows_columns ()
380362 return row1 , row2
381363
382364 def _range_tightbbox (self , x ):
383- """Gets span of tight bounding box, including twin axes and panels
384- which are not considered real children and so aren't ordinarily
385- included in the tight bounding box calc.
386- `~proplot.axes.Axes.get_tightbbox` caches tight bounding boxes when
365+ """Return the tight bounding box span from the cached bounding box.
366+ `~proplot.axes.Axes.get_tightbbox` caches bounding boxes when
387367 `~Figure.get_tightbbox` is called."""
388- # TODO: Better resting for axes visibility
368+ # TODO: Better testing for axes visibility
389369 bbox = self ._tightbbox
390370 if bbox is None :
391371 return np .nan , np .nan
@@ -466,47 +446,52 @@ def _reassign_title(self):
466446 pad = tax .xaxis .get_tick_padding ()
467447 tax ._set_title_offset_trans (self ._title_pad + pad )
468448
469- def _sharex_setup (self , sharex , level ):
470- """Sets up panel axis sharing."""
449+ def _sharex_setup (self , sharex , level = None ):
450+ """Configure x-axis sharing for panels. Main axis sharing is done in
451+ `~CartesianAxes._sharex_setup`."""
452+ if level is None :
453+ level = self .figure ._sharex
471454 if level not in range (4 ):
472455 raise ValueError (
473- 'Level can be 0 (share nothing), '
474- '1 (do not share limits, just hide axis labels), '
475- '2 (share limits, but do not hide tick labels), or '
476- '3 (share limits and hide tick labels). Got {level}.'
456+ 'Axis sharing level can be 0 (share nothing), '
457+ '1 (hide axis labels), '
458+ '2 (share limits and hide axis labels), or '
459+ '3 (share limits and hide axis and tick labels). Got {level}.'
477460 )
478- # enforce, e.g. if doing panel sharing
479- self ._sharex_level = max (self ._sharex_level , level )
480461 self ._share_short_axis (sharex , 'l' , level )
481462 self ._share_short_axis (sharex , 'r' , level )
482463 self ._share_long_axis (sharex , 'b' , level )
483464 self ._share_long_axis (sharex , 't' , level )
484465
485- def _sharey_setup (self , sharey , level ):
486- """Sets up panel axis sharing."""
466+ def _sharey_setup (self , sharey , level = None ):
467+ """Configure y-axis sharing for panels. Main axis sharing is done in
468+ `~CartesianAxes._sharey_setup`."""
469+ if level is None :
470+ level = self .figure ._sharey
487471 if level not in range (4 ):
488472 raise ValueError (
489- 'Level can be 0 (share nothing), '
490- '1 (do not share limits, just hide axis labels), '
491- '2 (share limits, but do not hide tick labels), or '
492- '3 (share limits and hide tick labels). Got {level}.'
473+ 'Axis sharing level can be 0 (share nothing), '
474+ '1 (hide axis labels), '
475+ '2 (share limits and hide axis labels), or '
476+ '3 (share limits and hide axis and tick labels). Got {level}.'
493477 )
494- self ._sharey_level = max (self ._sharey_level , level )
495478 self ._share_short_axis (sharey , 'b' , level )
496479 self ._share_short_axis (sharey , 't' , level )
497480 self ._share_long_axis (sharey , 'l' , level )
498481 self ._share_long_axis (sharey , 'r' , level )
499482
500483 def _share_setup (self ):
501- """Applies axis sharing for axes that share the same horizontal or
502- vertical extent, and for their panels ."""
484+ """Automatically configure axis sharing based on the horizontal and
485+ vertical extent of subplots in the figure gridspec ."""
503486 # Panel axes sharing, between main subplot and its panels
504- # Top and bottom
505487 def shared (paxs ):
506488 return [
507- pax for pax in paxs if not pax ._panel_filled
508- and pax ._panel_share ]
489+ pax for pax in paxs
490+ if not pax ._panel_filled and pax ._panel_share
491+ ]
492+
509493 if not self ._panel_side : # this is a main axes
494+ # Top and bottom
510495 bottom = self
511496 paxs = shared (self ._bpanels )
512497 if paxs :
@@ -529,16 +514,15 @@ def shared(paxs):
529514 iax ._sharey_setup (left , 3 )
530515
531516 # Main axes, sometimes overrides panel axes sharing
532- # TODO: This can get very repetitive, but probably minimal impact
533- # on performance?
517+ # TODO: This can get very repetitive, but probably minimal impact?
534518 # Share x axes
535519 parent , * children = self ._get_extent_axes ('x' )
536520 for child in children :
537- child ._sharex_setup (parent , parent . _sharex_level )
521+ child ._sharex_setup (parent )
538522 # Share y axes
539523 parent , * children = self ._get_extent_axes ('y' )
540524 for child in children :
541- child ._sharey_setup (parent , parent . _sharey_level )
525+ child ._sharey_setup (parent )
542526
543527 def _share_short_axis (self , share , side , level ):
544528 """Share the "short" axes of panels along a main subplot with panels
0 commit comments