Skip to content

MNT: Remove AxesStack and deprecated behavior of reuse of existing axes with same arguments #18832

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
lpsinger opened this issue Oct 28, 2020 · 7 comments · Fixed by #19153
Closed
Milestone

Comments

@lpsinger
Copy link
Contributor

Describe the issue

Summary

In Matplotlib 2.1, the behavior of reusing existing axes when created with the same arguments was deprecated (see #9037). The request is to finally remove this behavior.

My immediate motivation is that I have a collection of projection classes that take as a keyword argument an instance of astropy.coordinates.SkyCoord, which as of Astropy 4.1 are no longer hashable (see also astropy/astropy#9857). This unexpectedly broke my code because I had not realized that projection keyword arguments had to be hashable.

Proposed fix

Remove the AxesStack class, remove the Figure._make_key method, and update the documentation to reflect the removal of the old deprecated behavior.

@tacaswell tacaswell added this to the v3.4.0 milestone Oct 28, 2020
@tacaswell
Copy link
Member

@anntzer do you already have a branch for this?

@anntzer
Copy link
Contributor

anntzer commented Oct 28, 2020

IIRC I kind of gave up on that due to unclearness of what we want to keep supporting, e.g. wrt. gca(projection=..., ...) (#10700) (which goes through the same AxesStack info). Probably you need to make some executive decisions on that :)

@lpsinger
Copy link
Contributor Author

lpsinger commented Nov 1, 2020

@anntzer, after studying #10700, my suggestion is:

  1. In the next release of Matplotlib:
    • Deprecate kwargs for gca()
    • Remove projection kwargs lookup (for gca() and also subplots(), etc.)
    • If gca() is called without kwargs, simply return the current axes
    • If gca() kwargs matches the kwargs of the current axes, return those axes, otherwise raise an exception
  2. In a future release of Matplotlib:
    • Remove kwargs entirely from gca()

What do you think?

@anntzer
Copy link
Contributor

anntzer commented Nov 1, 2020

I am personally fine with fully deprecating all kwargs to gca(), but there was some pushback wrt. subplot() in #12513 (and IIRC these basically go through the same machinery) and I had little interest in fighting that fight, which is why I decided to let @tacaswell decide :)

@lpsinger
Copy link
Contributor Author

lpsinger commented Nov 8, 2020

@tacaswell, what do you think? I am happy to take a stab at the above changes, if you agree with the approach.

@lpsinger
Copy link
Contributor Author

How do we want to handle a call to gca() without kwargs when there are not yet any axes? Return None? Or return a new axes?

@anntzer
Copy link
Contributor

anntzer commented Nov 18, 2020

That should definitely return a new axes (I'd guess that's an extremely common use case (like it or not)).

lpsinger added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Nov 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Dec 6, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Dec 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Dec 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Dec 19, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Dec 20, 2020
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 7, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 11, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 19, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 19, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 19, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 19, 2021
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 added a commit to lpsinger/matplotlib that referenced this issue Jan 21, 2021
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 added a commit to lpsinger/ligo.skymap that referenced this issue Feb 19, 2021
lpsinger added a commit to lpsinger/ligo.skymap that referenced this issue Mar 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants