Skip to content

API: Remove deprecated axes kwargs collision detection #18978

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

Closed

Conversation

lpsinger
Copy link
Contributor

@lpsinger lpsinger commented Nov 19, 2020

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.

Functions that create new axes (axes, add_axes, subplot, etc.) will now always create new axes, regardless of whether the kwargs passed to them match already existing axes.

Passing kwargs to gca is deprecated. If gca is called with kwargs that do not match the current axes, then an exception is raised.

Fixes #18832.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] 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 branch 4 times, most recently from 0f59282 to 8540c04 Compare November 19, 2020 17:56
@tacaswell tacaswell added this to the v3.4.0 milestone Nov 19, 2020
@lpsinger
Copy link
Contributor Author

The Travis failure seems to be unrelated.

@tacaswell
Copy link
Member

tacaswell commented Nov 21, 2020

Well, it looks like the changes to the OSS version of travis have finally caught up with us safe to ignore that.

Reading more carefully the failure was unrelated to our builds getting suspended, it was trying to get an image from the network. I still agree we can disregard that for reviewing this PR.

tacaswell
tacaswell previously approved these changes Nov 21, 2020
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still a bit worried about this as changing how how axes are created seems like it should get extra consideration, however this has been warning from 2.1 which is more than fair warning.

@tacaswell tacaswell changed the title MNT: Remove deprecated axes kwargs collision detection API: Remove deprecated axes kwargs collision detection Nov 24, 2020
@tacaswell tacaswell dismissed their stale review November 24, 2020 20:52

Discussion on call convinced me we need a bit more thinking.

@tacaswell
Copy link
Member

#12513 for other discussion.

@tacaswell
Copy link
Member

Consusensus on the call was that we can not break

plt.subplot(222)
plt.subplot(222)

because as much as we think this is a bad idea (and holding onto the returned Axes object leads to significantly better code) there is no other way to "get back to" a previous axes using just the pyplot API. The logic for this re-use should fully live in pyplot.subplot and only check the subplot spec and warn if any kwargs are passed. The information we need to sort out if the given Axes exists in the Figure already exists on the Axes objects so we don't need to add any new state (just walk state we already have).

@jklymak
Copy link
Member

jklymak commented Nov 24, 2020

EDIT: sorry cross post with above....

I've not looked at all the changes here carefully, but can try to do so. However, as discussed on the weekly call, we need to make sure

ax0 = plt.subplot(2, 1, 1)
plt.subplot(2, 1, 2)
ax1 = subplot(2, 1, 1)
assert ax0 == ax1

still works, preferably without warning....

We did discuss the extra arguments case and decided that

ax0 = plt.subplot(2, 1, 1, polar=True)
plt.subplot(2, 1, 2)
ax1 = subplot(2, 1, 1, polar=False)   #  Warns about ignored kwargs
assert ax0 == ax1    # pass
ax2 = subplot(2, 1, 1, polar=True)   #  Warns about ignored kwargs
assert ax0 == ax2    # pass

should both warn that the second and third call has kwargs that are being ignored, rather than trying to check if the kwargs match the creation kwargs they should just be ignored. This precludes users from getting two axes over one another using pure pyplot, but they can still do this via non-pyplot:

ax0 = fig.add_subplot(2, 1, 1, polar=True)
ax1 = fig.add_subplot(2, 1, 1, polar=False)   # creates a *second* cartesian axes

Note that in that case, plt.subplot(2, 1, 1) will be somewhat ill-defined, in that it will return the first axes added.

Ping @tacaswell, @anntzer, @timhoffm in case I got any of that incorrect.

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.

Functions that create new axes (`axes`, `add_axes`, `subplot`, etc.)
will now always create new axes, regardless of whether the kwargs
passed to them match already existing axes.

Passing kwargs to `gca` is deprecated. If `gca` is called with
kwargs that do not match the current axes, then an exception is
raised.

Fixes matplotlib#18832.
@lpsinger lpsinger force-pushed the do-not-detect-axes-collisions branch from 8540c04 to 41b93d8 Compare December 6, 2020 19:39
@lpsinger
Copy link
Contributor Author

lpsinger commented Dec 6, 2020

@tacaswell, @jklymak, I've attempted to implement that behavior, but I am getting some unit test failures related to twin axes, and I'm a bit stuck. Would you take a look, please?

@lpsinger
Copy link
Contributor Author

I now understand the problem with twin axes. The method matplotlib.axes._subplots.SubplotBase._make_twin_axes calls matplotlib.figure.Figure.add_subplot, which in my implementation is still doing the key lookup.

To avoid this issue, is it OK if the logic for reusing an existing subplot lives only in matplotlib.pyplot.subplot, and not in its object-oriented sibling matplotlib.figure.Figure.add_subplot?

@QuLogic
Copy link
Member

QuLogic commented Jan 19, 2021

I think this PR was replaced by #19153.

jarrodmillman added a commit to jarrodmillman/scientific-python-lectures that referenced this pull request Sep 16, 2022
jarrodmillman added a commit to jarrodmillman/scientific-python-lectures that referenced this pull request Sep 16, 2022
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
4 participants