Skip to content

MNT: Warn if fixed aspect overwrites explicitly set data limits #28683

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 1 commit into from
Sep 26, 2024

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Aug 8, 2024

Closes #28673.

@@ -1705,7 +1705,8 @@ def set_adjustable(self, adjustable, share=False):
----------
adjustable : {'box', 'datalim'}
If 'box', change the physical dimensions of the Axes.
If 'datalim', change the ``x`` or ``y`` data limits.
If 'datalim', change the ``x`` or ``y`` data limits. This
may ignore explicitly defined axis limits.
Copy link
Member Author

@timhoffm timhoffm Aug 8, 2024

Choose a reason for hiding this comment

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

Note: I've intentionally written may because in the current implementation one can have scenarios where the limits are respected. For example

fig, ax = plt.subplots()
ax.set_aspect('equal', 'datalim')
ax.plot([0, 1], [0, 2])
ax.set_ylim(-5, 5)

Just looking at the data, the y-range is larger, so to get all data shown on equal aspect, x has to be increased. Thus, new xlims are calculated, but taking the ylim (not the ydata) into account. Whether this behavior of sometimes taking limits into account and sometimes not is desireable, is a separate question that I don't want to discuss. The doc now only states that it may (or may not) happen. Note however, that the added runtime warning is precise: It will be emitted exactly if we change previously fixed limits.

@timhoffm timhoffm added this to the v3.9.2 milestone Aug 8, 2024
@tacaswell
Copy link
Member

I do not think users will see this by default (or I may be confused about logging)?

@tacaswell
Copy link
Member

I also am not sure that we want to backport this. It is a minor change to long standing behavior.

@timhoffm
Copy link
Member Author

timhoffm commented Aug 8, 2024

I do not think users will see this by default (or I may be confused about logging)?

I checked in my dev environment (don't think I've configured something special there): python shell, ipython shell, python script all show this.

Alternative would be warnings.warn. From [logging tutorial(https://docs.python.org/3/howto/logging.html#logging-basic-tutorial)

Use warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning

That's the question: Do we see this as a misuse and want users to change their code? Or do we only want to inform? Given the somewhat peculiar behavior that this warning depends on the set limits and used data, I've been hesitant to request a code change, even if that means some logging configuration may not show the message.

I also am not sure that we want to backport this.

No strong opinion. I've mainly target 3.9.x to get the doc hint in. But we can also target 3.10.

@QuLogic QuLogic modified the milestones: v3.9.2, v3.9.3 Aug 12, 2024
@timhoffm timhoffm modified the milestones: v3.9.3, v3.10.0 Sep 16, 2024
Copy link
Member

@ksunden ksunden left a comment

Choose a reason for hiding this comment

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

Approved during discussion in community call

@ksunden ksunden merged commit e8e12df into matplotlib:main Sep 26, 2024
39 checks passed
@timhoffm timhoffm deleted the datalim branch September 26, 2024 20:40
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.

[Bug]: set_xlim, set_xbounds being ignored when set_aspect('equal', 'datalim') being used
5 participants