Skip to content

Use attributes Axes.x/yaxis instead of Axes.get_x/yaxis() #18709

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
Oct 13, 2020

Conversation

timhoffm
Copy link
Member

PR Summary

We're already largely doing this in code base and examples.

This PR changes some remaining usages and discourages the use of the
getters in their docstrings. For now I'm not going so far as to deprecate the
methods. Keeping them around does little harm.

Note on API consistency: While we generally use getters, I'm not too
worried that people may find this inconsistent. An axis is rather a
sub-part than a property. In particular, it will mostly be used as an
indirection to one of its properties, i.e. ax.xaxis.get_units().
Here we still have a final getter call. IMHO it even looks better / more
pythonic than a method chain: ax.get_xaxis().get_units().

I'm also not too worried that people may try to overwrite the plain
attributes Axes.x/yaxis. While one could turn them into properties
to protect overwriting, the attributes have already been used widely
in examples and we did not get any complaints.

We're already largely doing this in code base and examples.

This PR changes some remaining usages and discourages the use of the
getters in their docstrings.

*Note on API consistency*: While we generally use getters, I'm not too
worried that people may find this inconsistent. An axis is rather a
sub-part than a property. In particular, it will mostly be used as an
indirection to one of its properties, i.e. `ax.xaxis.get_units()`.
Here we still have a final getter call. IMHO it even looks better / more
pythonic than a method chain: `ax.get_xaxis().get_units()`.

I'm also not too worried that people may try to overwrite the plain
attributes `Axes.x/yaxis`. While one could turn them into properties
to protect overwriting, the attributes have already been used widely
in examples and we did not get any complaints.
@jklymak jklymak merged commit caaf3b7 into matplotlib:master Oct 13, 2020
@timhoffm timhoffm deleted the xaxis-yaxis branch October 13, 2020 19:00
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.

3 participants