Skip to content

Commit

Permalink
Permit diabling numbers with e.g. number=None
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd committed Oct 30, 2021
1 parent 0ffd649 commit f7308cb
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions proplot/figure.py
Expand Up @@ -295,10 +295,10 @@
These restrictions arise because we allocate a single,
unique `~Figure.gridspec` for each figure.
number : int, optional
The axes number used for a-b-c labeling. See `~proplot.axes.Axes.format`
for details. By default this is incremented automatically based on the other
subplots in the figure. Use ``0`` or ``False`` to ensure the subplot has no
a-b-c label. Note the number corresponding to ``a`` is ``1``, not ``0``.
The axes number used for a-b-c labeling. See `~proplot.axes.Axes.format` for
details. By default this is incremented automatically based on the other subplots
in the figure. Use e.g. ``number=None`` or ``number=False`` to ensure the subplot
has no a-b-c label. Note the number corresponding to ``a`` is ``1``, not ``0``.
autoshare : bool, optional
Whether to automatically share the *x* and *y* axes with subplots spanning the
same rows and columns based on the figure-wide `sharex` and `sharey` settings.
Expand Down Expand Up @@ -1168,7 +1168,7 @@ def add_axes(self, rect, **kwargs):

@docstring._concatenate_inherited
@docstring._snippet_manager
def add_subplot(self, *args, number=None, **kwargs):
def add_subplot(self, *args, **kwargs):
"""
%(figure.subplot)s
"""
Expand All @@ -1177,7 +1177,7 @@ def add_subplot(self, *args, number=None, **kwargs):
args = args or (1, 1, 1)
gs = self.gridspec

# Integer
# Integer arg
if len(args) == 1 and isinstance(args[0], Integral):
if not 111 <= args[0] <= 999:
raise ValueError(f'Input {args[0]} must fall between 111 and 999.')
Expand Down Expand Up @@ -1247,15 +1247,12 @@ def add_subplot(self, *args, number=None, **kwargs):
# to add_subplot() in mpl < 3.4 may return an already-drawn subplot in the
# wrong location due to gridspec override. Is against OO package design.
self.gridspec = gs # trigger layout adjustment
if number is None:
number = 1 + max(self._subplot_dict, default=0)
if number: # must be added for a-b-c labels
kwargs['number'] = number
self._subplot_counter += 1 # unique label for each subplot
kwargs.setdefault('label', f'subplot_{self._subplot_counter}')
kwargs.setdefault('number', 1 + max(self._subplot_dict, default=0))
ax = super().add_subplot(ss, _subplot_spec=ss, **kwargs)
if number:
self._subplot_dict[number] = ax
if ax.number:
self._subplot_dict[ax.number] = ax

return ax

Expand Down

0 comments on commit f7308cb

Please sign in to comment.