Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate position argument to Axes.apply_aspect() #23629

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
wants to merge 2 commits into from

Conversation

timhoffm
Copy link
Member

PR Summary

In itself apply_aspect() feels too low level to be needed by an end-user. I'm not sure if it reasonably works at all on its own. It might be that the result is influenced by other artists and if something is left stale, then the application result is still not final. In that case, one would need a full draw (without rendering) anyway. OTOH if apply_aspect() was really standalone, I don't know why we defer the application and don't apply it immediately when setting the aspect.

Also, the position parameter of apply_aspect does not seem a user-facing API. It is used internally by layout mechanisms. But shifting the position explicitly as part of aspect application seems overreach of the scope of the function and at least not something a user should do.

I'm 99% percent sure apply_aspect() does not need to be public API, but please speak up if you think otherwise. And even if we miss a justified use-case for a user. They should be able to give feedback during the deprecation period and we would reconsider then.

@tacaswell tacaswell added this to the v3.6.0 milestone Aug 15, 2022
@jklymak
Copy link
Member

jklymak commented Aug 17, 2022

I think if you search on stackoverflow there are quite a few answers that suggest calling apply_aspect to get the position of things after the proper aspect ratio is applied without forcing a full draw.

@jklymak
Copy link
Member

jklymak commented Aug 17, 2022

Well, maybe only a couple: https://stackoverflow.com/search?q=%5Bmatplotlib%5D+apply_aspect

@timhoffm
Copy link
Member Author

timhoffm commented Aug 18, 2022

Well, maybe only a couple: https://stackoverflow.com/search?q=%5Bmatplotlib%5D+apply_aspect

From these:

    1. and 5) only show apply_aspect in unrelated parts of a traceback.
  • 1), 2), 4) use it for a layout update because they want to query Axes sizes. - Note also that in 1 @tacaswell suggests "I strongly suspect that you just need to call draw after calling set_aspect."

Anyway, let's be super-safe and only deprecate the public position parameter for now. - No end user should manipulate the position through apply_aspect(). And I haven't seen anything in the wild.

@timhoffm timhoffm force-pushed the deprecate-apply-aspect branch from d0584cd to 9a68b94 Compare August 18, 2022 23:51
@QuLogic QuLogic changed the title Deprecate Axes.apply_aspect() Deprecate position argument to Axes.apply_aspect() Aug 18, 2022
@timhoffm timhoffm force-pushed the deprecate-apply-aspect branch from 9a68b94 to bdcaa9c Compare August 18, 2022 23:56
@QuLogic
Copy link
Member

QuLogic commented Aug 18, 2022

Please update the commit message as well for that.

@timhoffm timhoffm force-pushed the deprecate-apply-aspect branch 2 times, most recently from 7784ff2 to 38fbaad Compare August 19, 2022 00:05
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

I've found a use of apply_aspect in the wild that this rename would likely break without the deprecation triggering
https://github.com/AudioSceneDescriptionFormat/splines/blob/master/doc/rotation/helper.py#L275

I'm not entirely sure what they are attempting to do there.

@@ -0,0 +1,3 @@
The parameter *position* in ``Axes.apply_aspect()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... is deprecated. It is considered internal API and now public use case is known.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
... is deprecated. It is considered internal API and now public use case is known.
... is deprecated. It is considered internal API and no public use case is known.

Comment on lines 1869 to 1885
position : None or .Bbox

If not ``None``, this defines the position of the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
position : None or .Bbox
If not ``None``, this defines the position of the
position : None or .Bbox
If not ``None``, this defines the position of the

@QuLogic
Copy link
Member

QuLogic commented Aug 19, 2022

@timhoffm timhoffm modified the milestones: v3.6.0, v3.7.0 Aug 19, 2022
@timhoffm
Copy link
Member Author

timhoffm commented Aug 19, 2022

Deferred to 3.7. Let’s not rush this into 3.6.

This needs a more thorough investigation.

@timhoffm timhoffm marked this pull request as draft August 19, 2022 07:50
@timhoffm timhoffm modified the milestones: v3.7.0, future releases Dec 15, 2022
@timhoffm
Copy link
Member Author

timhoffm commented Jun 3, 2024

Digging through the history my understanding of the reason for the position parameter is the following:

It is somewhat surprising that "_apply_aspect" takes an optional position as input, which seems more functionality than what the name suggests.

The parameter was introduced in 66290aae. Generally, applying an aspect will modify the size and position of an Axes. The fact that position is updated anyway was used to funnel additional position information from a layoutinto the already existing positioning code.

IMHO:

  • The position parameter should never be used by an end-user.
  • The function _apply_aspect should rather be called update_geometry or similar.

I see two ways forward:

  1. Simply document that position is not meant to be user-facing. And don't bother further with the topic.
  2. Go further with a formal deprecation, which means we need a public apply_aspect() that will become parameter-less. And we need a new private API to carry the position. This has compatibility implications for 3rd party Axes subclasses (see @QuLogic's links above).

I'm inclined to go with 1.


One use of apply_aspect that maybe could be a draw: https://github.com/hannorein/rebound/blob/main/rebound/plotting.py#L103-L107

has meanwhile been changed to a draw. 👍

timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jun 4, 2024
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jun 4, 2024
Superseeds matplotlib#23629.

It is somewhat surprising that "_apply_aspect" takes an
optional position as input, which seems more functionality
than what the name suggests.

The parameter was introduced in 66290aa. Generally, applying
an aspect will modify the size and position of an Axes. The
fact that position is updated anyway was used to funnel
additional position information from a layout into the already
existing positioning code.

Deprecating and removing the parameter would be a medium compatibility
hassle. Therefore, I chose only to document the status quo and its
intention, so that users are less surprised. See
matplotlib#23629 (comment)
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jun 4, 2024
Superseeds matplotlib#23629.

It is somewhat surprising that "_apply_aspect" takes an
optional position as input, which seems more functionality
than what the name suggests.

The parameter was introduced in 66290aa. Generally, applying
an aspect will modify the size and position of an Axes. The
fact that position is updated anyway was used to funnel
additional position information from a layout into the already
existing positioning code.

Deprecating and removing the parameter would be a medium compatibility
hassle. Therefore, I chose only to document the status quo and its
intention, so that users are less surprised. See
matplotlib#23629 (comment)
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jun 4, 2024
Superseeds matplotlib#23629.

It is somewhat surprising that "_apply_aspect" takes an
optional position as input, which seems more functionality
than what the name suggests.

The parameter was introduced in 66290aa. Generally, applying
an aspect will modify the size and position of an Axes. The
fact that position is updated anyway was used to funnel
additional position information from a layout into the already
existing positioning code.

Deprecating and removing the parameter would be a medium compatibility
hassle. Therefore, I chose only to document the status quo and its
intention, so that users are less surprised. See
matplotlib#23629 (comment)
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jun 4, 2024
Superseeds matplotlib#23629.

It is somewhat surprising that "_apply_aspect" takes an
optional position as input, which seems more functionality
than what the name suggests.

The parameter was introduced in 66290aa. Generally, applying
an aspect will modify the size and position of an Axes. The
fact that position is updated anyway was used to funnel
additional position information from a layout into the already
existing positioning code.

Deprecating and removing the parameter would be a medium compatibility
hassle. Therefore, I chose only to document the status quo and its
intention, so that users are less surprised. See
matplotlib#23629 (comment)
@timhoffm
Copy link
Member Author

Not going forward with the deprecation. The parameter is now documented as internal and that's good enough.

@timhoffm timhoffm closed this Sep 25, 2024
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.

4 participants