Skip to content

MNT: Remove deprecated axes kwargs collision detection (version 2) #19153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/19153-LPS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``pyplot.gca()``, ``Figure.gca``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing keyword arguments to `.pyplot.gca` or `.figure.Figure.gca` will not be
supported in a future release.
21 changes: 21 additions & 0 deletions doc/users/next_whats_new/axes_kwargs_collision.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Changes to behavior of Axes creation methods (``gca()``, ``add_axes()``, ``add_subplot()``)
-------------------------------------------------------------------------------------------

The behavior of the functions to create new axes (`.pyplot.axes`,
`.pyplot.subplot`, `.figure.Figure.add_axes`,
`.figure.Figure.add_subplot`) has changed. In the past, these functions would
detect if you were attempting to create Axes with the same keyword arguments as
already-existing axes in the current figure, and if so, they would return the
existing Axes. Now, these functions will always create new Axes. A special
exception is `.pyplot.subplot`, which will reuse any existing subplot with a
matching subplot spec. However, if there is a subplot with a matching subplot
spec, then that subplot will be returned, even if the keyword arguments with
which it was created differ.

Correspondingly, the behavior of the functions to get the current Axes
(`.pyplot.gca`, `.figure.Figure.gca`) has changed. In the past, these functions
accepted keyword arguments. If the keyword arguments matched an
already-existing Axes, then that Axes would be returned, otherwise new Axes
would be created with those keyword arguments. Now, the keyword arguments are
only considered if there are no axes at all in the current figure. In a future
release, these functions will not accept keyword arguments at all.
12 changes: 1 addition & 11 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import uuid

from matplotlib import _api, docstring
import matplotlib.artist as martist
Expand Down Expand Up @@ -142,16 +141,7 @@ def _make_twin_axes(self, *args, **kwargs):
# which currently uses this internal API.
if kwargs["sharex"] is not self and kwargs["sharey"] is not self:
raise ValueError("Twinned Axes may share only one axis")
# The dance here with label is to force add_subplot() to create a new
# Axes (by passing in a label never seen before). Note that this does
# not affect plot reactivation by subplot() as twin axes can never be
# reactivated by subplot().
sentinel = str(uuid.uuid4())
real_label = kwargs.pop("label", sentinel)
twin = self.figure.add_subplot(
self.get_subplotspec(), *args, label=sentinel, **kwargs)
if real_label is not sentinel:
twin.set_label(real_label)
twin = self.figure.add_subplot(self.get_subplotspec(), *args, **kwargs)
self.set_adjustable('datalim')
twin.set_adjustable('datalim')
self._twinned_axes.join(self, twin)
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ def __len__(self):
def __getitem__(self, ind):
return self._elements[ind]

def as_list(self):
return list(self._elements)

def forward(self):
"""Move the position forward and return the current element."""
self._pos = min(self._pos + 1, len(self._elements) - 1)
Expand Down
Loading