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

Conversation

lpsinger
Copy link
Contributor

This replaces #18978, and addresses the comments from @tacaswell and @jklymak to preserve the behavior of repeated calls to plt.subplot with the same subplot spec.

PR Summary

In Matplotlib 2.1, the behavior of reusing existing axes when created with the same arguments was deprecated (see #9037). This behavior is now removed.

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.

Fixes #18832.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch 2 times, most recently from a886c4e to bcee8ab Compare December 19, 2020 04:25
@jklymak
Copy link
Member

jklymak commented Dec 19, 2020

This new behaviour sounds right to me, but have you tested it all? ie. I do not see a test that we create new axes, but maybe I read too quickly.

@lpsinger
Copy link
Contributor Author

@jklymak, I did not add any new unit tests. I only modified existing unit tests so that they would pass.

@lpsinger
Copy link
Contributor Author

lpsinger commented Jan 5, 2021

Hi, any feedback on this PR? This is just a gentle poke because the submission was badly timed, right before the holidays. Thank you!

@jklymak
Copy link
Member

jklymak commented Jan 5, 2021

Please do keep pinging us! OTOH, the ball is still in your court to add new tests for the new behaviour ;-)

@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch from e6df62e to f0ca259 Compare January 7, 2021 16:34
@lpsinger
Copy link
Contributor Author

lpsinger commented Jan 7, 2021

@jklymak, as requested, I added a unit test.

@jklymak
Copy link
Member

jklymak commented Jan 7, 2021

@jklymak, as requested, I added a unit test.

Thanks a lot, the unit tests really make the new behaviour clear. This all seems reasonable to me, but lets ping @tacaswell, @timhoffm and @QuLogic to make sure we have all that was discussed in #18978 correct.

@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch from f6d425f to 400aa25 Compare January 11, 2021 22:01
@lpsinger
Copy link
Contributor Author

@timhoffm, thank you, I addressed all of your comments.

@timhoffm timhoffm added this to the v3.4.0 milestone Jan 12, 2021
@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch 3 times, most recently from 78d231f to 0db9c6c Compare January 19, 2021 13:17
@lpsinger
Copy link
Contributor Author

@QuLogic, I believe that I addressed all of your comments.

@lpsinger lpsinger requested a review from QuLogic January 19, 2021 13:19
@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch from 0db9c6c to 2377702 Compare January 19, 2021 16:32
@QuLogic
Copy link
Member

QuLogic commented Jan 20, 2021

It looks like you'll need to update the tests for the wording changes.

In Matplotlib 2.1, the behavior of reusing existing axes when
created with the same arguments was deprecated (see matplotlib#9037). This
behavior is now removed.

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.

Fixes matplotlib#18832.
@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions-v2 branch from 2377702 to 68498c6 Compare January 21, 2021 14:04
@lpsinger
Copy link
Contributor Author

It looks like you'll need to update the tests for the wording changes.

Whoops! Should be fixed now.

@QuLogic QuLogic merged commit b5e714a into matplotlib:master Jan 22, 2021
@lpsinger lpsinger deleted the do-not-detect-axes-collisions-v2 branch January 22, 2021 04:01
@QuLogic QuLogic mentioned this pull request Jan 22, 2021
6 tasks
lpsinger added a commit to lpsinger/matplotlib that referenced this pull request Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MNT: Remove AxesStack and deprecated behavior of reuse of existing axes with same arguments
5 participants