Skip to content

Commit b5e714a

Browse files
authored
Merge pull request #19153 from lpsinger/do-not-detect-axes-collisions-v2
MNT: Remove deprecated axes kwargs collision detection (version 2)
2 parents 12ed239 + 68498c6 commit b5e714a

File tree

9 files changed

+246
-286
lines changed

9 files changed

+246
-286
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``pyplot.gca()``, ``Figure.gca``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Passing keyword arguments to `.pyplot.gca` or `.figure.Figure.gca` will not be
5+
supported in a future release.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Changes to behavior of Axes creation methods (``gca()``, ``add_axes()``, ``add_subplot()``)
2+
-------------------------------------------------------------------------------------------
3+
4+
The behavior of the functions to create new axes (`.pyplot.axes`,
5+
`.pyplot.subplot`, `.figure.Figure.add_axes`,
6+
`.figure.Figure.add_subplot`) has changed. In the past, these functions would
7+
detect if you were attempting to create Axes with the same keyword arguments as
8+
already-existing axes in the current figure, and if so, they would return the
9+
existing Axes. Now, these functions will always create new Axes. A special
10+
exception is `.pyplot.subplot`, which will reuse any existing subplot with a
11+
matching subplot spec. However, if there is a subplot with a matching subplot
12+
spec, then that subplot will be returned, even if the keyword arguments with
13+
which it was created differ.
14+
15+
Correspondingly, the behavior of the functions to get the current Axes
16+
(`.pyplot.gca`, `.figure.Figure.gca`) has changed. In the past, these functions
17+
accepted keyword arguments. If the keyword arguments matched an
18+
already-existing Axes, then that Axes would be returned, otherwise new Axes
19+
would be created with those keyword arguments. Now, the keyword arguments are
20+
only considered if there are no axes at all in the current figure. In a future
21+
release, these functions will not accept keyword arguments at all.

lib/matplotlib/axes/_subplots.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import functools
2-
import uuid
32

43
from matplotlib import _api, docstring
54
import matplotlib.artist as martist
@@ -142,16 +141,7 @@ def _make_twin_axes(self, *args, **kwargs):
142141
# which currently uses this internal API.
143142
if kwargs["sharex"] is not self and kwargs["sharey"] is not self:
144143
raise ValueError("Twinned Axes may share only one axis")
145-
# The dance here with label is to force add_subplot() to create a new
146-
# Axes (by passing in a label never seen before). Note that this does
147-
# not affect plot reactivation by subplot() as twin axes can never be
148-
# reactivated by subplot().
149-
sentinel = str(uuid.uuid4())
150-
real_label = kwargs.pop("label", sentinel)
151-
twin = self.figure.add_subplot(
152-
self.get_subplotspec(), *args, label=sentinel, **kwargs)
153-
if real_label is not sentinel:
154-
twin.set_label(real_label)
144+
twin = self.figure.add_subplot(self.get_subplotspec(), *args, **kwargs)
155145
self.set_adjustable('datalim')
156146
twin.set_adjustable('datalim')
157147
self._twinned_axes.join(self, twin)

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ def __len__(self):
606606
def __getitem__(self, ind):
607607
return self._elements[ind]
608608

609+
def as_list(self):
610+
return list(self._elements)
611+
609612
def forward(self):
610613
"""Move the position forward and return the current element."""
611614
self._pos = min(self._pos + 1, len(self._elements) - 1)

0 commit comments

Comments
 (0)