-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Idea: unite xlim and set_xlim to same function #15938
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
Comments
Even if we did this, we wouldn't be able to replace e.g. ax.set_title() by ax.title() (for similarity with plt.title() because ax.title already exists (that's the Text object)), so I don't think this is a good idea... On the other hand, we could add all the set_foo synonyms to pyplot (plt.set_xlim(), plt.set_title(), ...) and encourage their use... |
Good point with ax.title(). My suggestion was more that it is possible to write ax.set_xlim as well as ax.xlim for valid options to adjust the range of the plot. I find your idea of plt.set_xlim() not so pretty because it is more verbose. Thanks for your answer! |
|
Changing/adding an alias for ax.set_title() to ax.ax_title() or from ax.set_xlim() to ax.xlim() is basically a nonstarter. |
TL;DR In summary, this is a major decision which would need careful consideration. As of now We need to be extremely careful when adding new API and new patterns. In particular, I suspect that supporting For sure such changes should not be implemented on single functions. If we want to go that direction, it would have to be consistently all over the (pyplot) library. There's also the question if we should support properties in the OO interface (but not going into the details of the pro's and con's of that now). What we can do right now Additional thoughs |
As a less experienced matplotlib user I can don't have an clear idea of function-names in the pyplot and OO style. fig, ax = plt.subplots()
line, = ax.plot(t, s, lw=2)
ax.annotate(... And I would not have known that it is possible to just write plt.annotate(... also, with the same logic as with ax.set_annotate(...
plt.annotate(... Therefore I support the idea of the separation on the API level. |
My proposal would allow you to mechanically translate import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax.set_ylim(-2, 2)
plt.show() to import numpy as np
import matplotlib.pyplot as plt
# fig, ax = plt.subplots() # remove this line
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = plt.plot(t, s, lw=2)
plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05),
)
plt.set_ylim(-2, 2) # the only API change needed
plt.show() |
The “set” prefix means you are settings a property to some value. Annotate is not a property it’s a new artist, therefore it doesn’t make sense to set it. You could argue that it should get a create_annotate or some such, but that grammar was not chosen a long time ago. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This comes up in some form once a year or so. My inclination is to close this with no action. From 2019 we have:
My pitch for evolving the pyplot (implicit) API towards the explicit API is #9111 |
Also #29272 adds a description https://matplotlib.org/stable/users/explain/api_interfaces.html how to translate between the Axes and the pyplot interface. I'm going to close this, because the API change would be too large. |
I think it is confusing that the limits are normally set by
xlim
and in subplots byset_xlim
.Would it not be nice to use the same name
ax.xlim(0,1)
for subplots ?The text was updated successfully, but these errors were encountered: