-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Prefer add_subplot(foo=bar) to subplots(subplot_kw={"foo": bar}). #14411
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.
Makes sense to me
+0.5. I think, this is more readable for the cases presented here. I'm a bit worried on the So if we're going away from "just use |
The advantage of |
I agree that the explicit figure creation has its merit, and partly withdraw my argument that This whole axes creation is a bit of a mess. If we did not have history
would look like a reaonable API to me (maybe with optional pyplot shortcuts using implicit figure creation). But we're not there. The latter is I'm really worried we're confusing users with all these different methods and changed recommendations for axes creation. Even if Essentially, I see two reasonable ways:
This is just an of-the-top of my head concept and certainly would need more thorough consideration. |
Well, I would really have preferred to have I agree that ever-changing recommendations are not great :( but OTOH we're all (well, at least I'm definitely still) learning how to best design an API. I guess this discussion is also colliding with #14421 now. |
I'm not a fan of favouring a different API for a single subplot than for multiple subplots, and I'm not at all a fan of |
Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it. |
Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it. |
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'm still very undecided between subplots(..., subplot_kw=...)
and figure().add_subplot()
.
Personally, I likely wouldn't actively rewrite this, but also wouldn't block if you push this forward again.
We should definitively limit the kwargs to polar and 3d. Everything else (see suggestions) should not be crammed into the subplots creation. This is a change that can be made independently of above decision.
When creating a single subplot I think the former is more readable. (Note that before mpl3.1 one had to write `add_subplot(111, foo=bar)` where the tradeoff was less clear.)
OK, I rewrote the whole thing to just make the changes that should be uncontroversial. |
Uh I hate to jump in this late but I'm concerned about the
My concern is w/ the folks who won't realize it's a chained call...I know the () should be a giveaway but I don't think it will be. I'd rather go all the way explicit here and use the unchained construction and leave "you can chain" to a section of the user guide or a tutorial. |
I think a crucial point of python semantics as opposed to matlab (which is still pretty commonly used in my field) is exactly that you can chain calls, i.e. |
I don't disagree in the case where they're definitely not going to use the figure object, but my concern is that this is example gallery code where the expectation is folks will c&p and then tweak. I think I agree w/ @jklymak that we should probably pin down a standard. |
Let's just close this until we can actually decide on a standard. |
re: deciding on a standard: Is there an existing standard for constructing a figure / axes / subplots? I see this in Getting Started:
Given that figure/ax construction is both super confusing for beginners and ubiquitous for using mpl, I think that specifically warrants a standard that the gallery examples really stick to. That way users can focus on the feature they're looking for, without having to detangle how the figure is constructed. If a different setup is unavoidable or nonsensical for 3D projections etc, it may be worth anticipating confusion by adding a link at the bottom of the example page to the quick start guide or another tutorial that explains the difference in setup. That seems to me to be potentially a separate question from a standard about using chained calls in general. I'm ambivalent there -- it seems easier to figure out when it's later on in the code, but I would avoid shortcuts in the setup. And FWIW, personally I think |
We have already added width_ratio and height_ratio as pass throughs. The only one I really miss is facecolor I think in general passing the figure back to the user is quite often necessary even in the case of a single subplot - in particular for colorbars. We could have ax.colorbar but again, having a separate idiom for single axes versus multiple axes in the docs seems confusing. I think we should always use fig, axs = plt.subplots() for consistency, even if there is just one axes. |
While technical possible, this is an anti-pattern IMHO. We should keep Axes creation and customization separate. Extracted from matplotlib#14411.
While technical possible, this is an anti-pattern IMHO. We should keep Axes creation and customization separate. Extracted from matplotlib#14411.
When creating a single subplot I think the former is more readable.
(Note that before mpl3.1 one had to write
add_subplot(111, foo=bar)
where the tradeoff was less clear.)
Happy to discuss which form to prefer...
PR Summary
PR Checklist