-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add "standard" Axes wrapper getters/setters for Axis invertedness. #29074
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
Conversation
f5764c9
to
3c6eca7
Compare
My 2 cents:
In the spirit of API consistency, we should move away from the old functions. This means at least discouraging. I'm unsure on deprecation. As an replacement, I'd be fine with having inversion only available on the axis and thus reduce the Axes API footprint. This would mean you don't get the standard axes property benefits like But if you feel strongly, that we should pull this up into the Axes API, I'd be ok with it as well. |
FWIW I do (Yes, I could write |
I was going to say that images invert the axis all the time. Also in my field, we plot depth on an inverted axis all the time. Just to say that I don't think inverting an axis is very rare. I think the proposed changes here are straight forward enough that they are OK from an API point of view - I agree that its not nice to have many ways to do the same thing, but in this case "the same thing" is pretty straight forward and well-defined. |
Semi-OT: Reason why Note:
|
@anntzer can you please discourage use of the old syntax?
|
An inverted y-axis is also common in atmospheric science, when we plot against pressure. |
Edited as suggested by @timhoffm. |
Logically 👍 You need to fix the linting errors. And I don't know what to make of the failing tests. Somehow 3d stuff seems broken. |
Doc build failures are real (reference issues related to the PR). |
Currently, toggling an axis invertedness requires either using the Axes method `ax.invert_xaxis()` (whose effect depends on whether it has already been called before) or going through the axis method `ax.xaxis.set_inverted()`; likewise, querying invertedness state requires either using the `ax.xaxis_inverted()` method, which has slightly nonstandard naming, or going through the axis method `ax.xaxis.get_inverted()`. For practicality, provide getters and setters with standard names: `ax.get_xinverted()`/`ax.set_xinverted()` (and likewise for y/z). In particular, the "standard" setter can be used with the multi-setter Artist.set(), or directly when creating the axes (`add_subplot(xinverted=True)`).
xaxis_inverted = _axis_method_wrapper("xaxis", "get_inverted") | ||
if xaxis_inverted.__doc__: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__doc__
can be unset in "optimized" mode (https://docs.python.org/3/using/cmdline.html#cmdoption-OO). There's already a few other places in the codebase with the same check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, still not following what this does or why... Is this because we are building __doc__
dynamically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in optimized mode the following line `xaxis_inverted.doc += …” would raise and therefore must be guarded.
Hello, I noticed in the Highlights of v3.10.0 it mentions Standard getters/setters for axis inversion state. However, on my Windows machine, I am actually unable to access the matplotlib.axes.Axes.get_xinverted function in |
@ksunden that should not be in the release notes; this change landed far too late for 3.10, and wasn't backported. |
Currently, toggling an axis invertedness requires either using the Axes method
ax.invert_xaxis()
(whose effect depends on whether it has already been called before) or going through the axis methodax.xaxis.set_inverted()
; likewise, querying invertedness state requires either using theax.xaxis_inverted()
method, which has slightly nonstandard naming, or going through the axis methodax.xaxis.get_inverted()
.For practicality, provide getters and setters with standard names:
ax.get_xinverted()
/ax.set_xinverted()
(and likewise for y/z). In particular, the "standard" setter can be used with the multi-setter Artist.set(), or directly when creating the axes(
add_subplot(xinverted=True)
).PR summary
PR checklist