| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
In general this seems good. OTOH I have been considering whether constrained_layout (or tight_layout) even needs to be part of the figure creation anymore. It definitely needs to be part of figure drawing... The point being that we could imagine other layout managers, and maybe this kwarg could take a class that does the layout? |
Sorry, something went wrong.
It's reasonable to have the layout mechanism as state on the Figure. And for practicality, configuring that state during creation is reasonable. It may well be that we don't have to actually do anything with that information until draw time.
This is quite analogous to the projection case where accept some strings, but also classes. For that generalization we'd need a layout manager interface description though. But from the user-facing API, the layout parameter is compatible with such an extension. |
Sorry, something went wrong.
|
Maybe
This leaves us open in the future to have these be user-constructible, and just have a draw-hook that calls layout.execute() at draw time. It'd be nice to get 20016 in so it'd be nice to hammer this out |
Sorry, something went wrong.
There was a problem hiding this comment.
This looks good. Suggest we get the string-only version working first. Then one of us can follow up with the layout super-class as a possible argument. I'm 99.9% sure this can be done for CL without a problem, and actually will fix some issues with it not updating to changes in things like the widths kwarg to gridspec. i.e. a new layout algorithm will just build itself at draw time. I don't think that will be much slower, if at all if I'm smart about caching.
Sorry, something went wrong.
|
looks good, I think some of the docs need adjusting now. |
Sorry, something went wrong.
|
You mean examples? |
Sorry, something went wrong.
|
No I mean we aren't accepting a dict... |
Sorry, something went wrong.
|
I think this is a welcome API improvement. Just two thoughts about naming... I would again (cf. a gitter conversation from a little while back) make a plug for naming the "constrained" operation something that describes the result, not something that describes the implementation. Second, in terms of the parameter name, "layout" suggests something about the general position of the subplots, not the method for "cleaning up" their fine positioning and extents. In fact, I just checked, and "layout" is the name of the parameter for the arrangement of the subplots in subplot_mosaic. Feels like that's bound to cause confusion... |
Sorry, something went wrong.
|
Not sure there is appetite to change the name of constrained_layout. But fair enough about this not being strictly the layout. Maybe layout_engine, layout_algorithm, layout_method? None are as concise as layout, but leaving layout off would make it too enigmatic. |
Sorry, something went wrong.
|
Appreciate the reluctance to change the name; I mention it because this API change would be the moment to do it, if it's going to happen. My expectation would be that keeping "constrained" will lead to relative disuse of the feature. Given the choice between "tight" and "constrained", "tight" sounds better to me. All of the bigrams are better names, but require so much typing :( If it were up to me, I would search for a parameter name that is more concise and corresponds more closely to exactly what the feature does, which is automatically arrange the subplots for optimal use of space. So, some synonym of "arrange", "marshal", "cleanup" might make sense... |
Sorry, something went wrong.
|
I appreciate the naming considerations. I've chosen the names for maximal recognizability [kind]_layout=True --> layout='[kind]'. subplot_mosaic(layout, ..., **fig_kw) is indeed a show stopper. We should not have a figure parameter with the same name, because it cannot be passed. Two options (both viable in principle):
For 1. we could go with subplot_mosaic(arrangement, ...) or similar. I'm a bit wed to layout because it's already used for these operations in the code. Also it reminds me of the Qt layout system. Neither of "arrange", "marshal", "cleanup" talk to me in this context. Some other possibilities: figure(... positioning='tight'), figure(..., adjustment='tight'), figure(..., spacing='tight'). |
Sorry, something went wrong.
That seems reasonable to me, if it makes sense to @tacaswell and @story645 That still doesn't say if layout is the right choice here. I don't know that typing something longer is the end of the world. After all, we have been typing constrained_layout=True the whole time, so layout_optimizer='constrained' isn't that bad. |
Sorry, something went wrong.
|
Does this need to be propagated to the docstrings of the pyplot functions? |
Sorry, something went wrong.
|
I agree with your statement of what the feature does. Name: I think spacing (or optimize_spacing) is good. default: I guess I almost always use constrained_layout=True. However, I am somewhat leery about a complicated algorithm as the default. For instance it can go wrong sometimes, and lead to quite strange layouts (mostly when an end-user has specified positions in physical units so that there is no way to satisfy the constraints). For prior art of magic causing problems, the inline backend in jupyter does bbox_inches="tight" by default, which causes a lot of confusion for users (I would guess there are 2-3 stackoverflow questions about this a week). |
Sorry, something went wrong.
How many questions a week do you think there would be along the lines of "why are my axis labels cut off in matplotlib" if it weren't the default, though? |
Sorry, something went wrong.
I don't think any of the other backends do this by default, so while I'm sure there are some questions along those lines, they are usually answered by "use tight_layout". But the point is well-taken that if 95% of plots are made with tight_layout turned on (and I bet that is not an exaggeration), maybe a spacing manager should be on by default. |
Sorry, something went wrong.
|
I think the inline backends bbox_inches="tight" is not quite comparable. Automatic cutting is surprising (you specify a figsize, but the figure ends up smaller). I don't expect that a resonable automatic, spacing is surprising. Concerning the corner cases: We should be able to detect cases where constraints cannot be fulfilled and fall back to now layout with a warning. |
Sorry, something went wrong.
|
Since this is a significant change, I would like to briefly discuss this in the next dev call.
Depending on these questions, I propse the following parameter name:
|
Sorry, something went wrong.
|
I can't make this week's call unfortunately. But we could do the following week. I think we should allow "extensions". When thinking about this, this is all really just a draw-time hook, and we have a drawtime callback. Regardless I like having it be its own kwarg as that is less mysterious. |
Sorry, something went wrong.
|
We decided in the dev call today to name the parameter layout because that is the most intuitive transition (tight_layout=True -> layout='tight'). The name may not be perfect but it's good enough. Also that pandas is using layout for the subplot arrangement is not a great worry. It's in a distant enough context that it should not be confusing. And we plan to propose to them to switch from subplots=True, layout=(2, 2) to subplots=(2, 2). |
Sorry, something went wrong.
There was a problem hiding this comment.
Minus the rebase.
Sorry, something went wrong.
|
Whats the plan here @timhoffm - here must be very many places where this needs to be changed in the docs? The test coverage is also null at the moment? |
Sorry, something went wrong.
|
I was going to merge and leave docs for later, but I think we definitely want some sort of test coverage at least. |
Sorry, something went wrong.
|
I don't know if we can leave the docs this way unless this waits for 3.6 |
Sorry, something went wrong.
|
I think it's ok to change the docs later for API changes that are only discouraging existing behavior. The transition on the user side is gradual anyway and there is no deadline to catch. So it's not the end of the world if somebody sees the old way in an example and still uses that. Of course, we want to encourage the new API and the docs should reflect that. They should follow soonish, whether for 3.5.0 or 3.5.1 does not matter too much. Having the new API is more important than advertizing it. If we delay this to 3.6, we force all users / downstream libraries that want to use it to a min. dependency of 3.6, which will delay adoption. |
Sorry, something went wrong.
|
I'm happy if somebody could add a test or two. It should be straight forward to adapt an existing layout test / make an image comparision, but I have little bandwidth right now. |
Sorry, something went wrong.
|
I added tests and changed the exception to use the _api wrapper. |
Sorry, something went wrong.
|
anyone can merged on green, happy to merge the tests on just my review of @QuLogic 's work. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Having separate and competing parameters tight_layout and constrained_layout is not a great API choice and can cause confusion
(#17339).
This PR addresses the problem by introducing a new parameter layout and suggests to use it instead.
Since tight_layout has been around for ages and is used probably a lot, I dare not right away deprecate the parameters and force all users to adapt. Therefore, tight_layout and constrained_layout are only marked as "discouraged" for now. (We might deprecate eventually some versions down the road). This is somewhat cumbersome, but IMHO the best way forward.
I put the "discouraged" concept in as a proposal. This adds a bit of overhead in the docs and code-wise, but gently paves the way for a better API. Feedback is welcome.
If this gets accepted, there will be followup actions: