-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Avoid using axis([xlo, xhi, ylo, yhi])
in examples.
#14149
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
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.
Not a big fan of the set()
function, but it's at least more clear than axis()
.
Should we add a comment to axis()
that it's recommended to set axes limits via set_x/ylim
(or set(xlim=...)
)?
I wouldn't bother for this PR, whose point is only to make the examples a bit more readable (to my taste at least). |
Doesn't necessarily have to be within this PR. I was just wondering, if we don't want to use this pattern in the examples, maybe we should tell users that it's not the preferred way to do it. - Or do we want to leave it as an equally accepted way of working in the API? I don't think this will be deprecated ever, but maybe discouraged. |
I added the alternate form in the docstring of |
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.
I'll merge as an improvement, though I don't particularly like ax.set(xlim=[x0, x1])
either
I think this is ready to be merged. Not sure if this is only failing due to the pytest 4.5 issue. @anntzer can you please rebase? |
In my view, `axis()` does too much: it can manipulate axis limits, axes aspect ratio, lines and label visibility, etc. This PR replaces in the examples `axis([xlo, xhi, ylo, yhi])` by `set(xlim=(xlo, xhi), ylim=(ylo, yhi))` (or `plt.xlim(xlo, xhi); plt.ylim(xlo, yhi)` for pyplot examples), which is easier to intuit IMO. There are also cases where I just remove the call to axis() when it doesn't add much to the example. Special cases: - anscombe can be greatly shortened by using shared axes. Note that the "old" xlims (2, 20) were immediately overwritten by xticks=(0, 10, 20) which expanded the xlims to (0, 20)... - fonts_demo/fonts_demo_kw are better showcased using figtext() anyways. - In pcolor_demo, the call to axis() is unneeded (pcolor/pcolormesh correctly set the artist sticky edges to have the right bounds). - In pyplot_formatstr (which could probably be deleted...), the call to axis() does not showcase anything. - In slider_demo, margins(x=0) is semantically more correct.
rebased |
Thanks. |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
…v3.1.x Backport PR #14149 on branch v3.1.x
In my view,
axis()
does too much: it can manipulate axis limits, axesaspect ratio, lines and label visibility, etc.
This PR replaces in the examples
axis([xlo, xhi, ylo, yhi])
byset(xlim=(xlo, xhi), ylim=(ylo, yhi))
(orplt.xlim(xlo, xhi); plt.ylim(xlo, yhi)
for pyplot examples), which iseasier to intuit IMO.
There are also cases where I just remove the call to axis() when it
doesn't add much to the example.
Special cases:
the "old" xlims (2, 20) were immediately overwritten by xticks=(0, 10,
20) which expanded the xlims to (0, 20)...
correctly set the artist sticky edges to have the right bounds).
to axis() does not showcase anything.
PR Summary
PR Checklist