Add facetgrid_figsize option to set_options#11158
Add facetgrid_figsize option to set_options#11158kkollsga wants to merge 5 commits intopydata:mainfrom
Conversation
|
Could you add before and after plots? |
headtr1ck
left a comment
There was a problem hiding this comment.
I don't really see the usecase, but if you went through the effort of setting up a PR there must be some :)
LGTM.
|
Thanks for the review. The use case comes from #11103, users with matplotlib stylesheets for fixed-size publication figures (IEEE, AGU, etc.) or corporate style guides, where col=/row= silently overrides their rcParams['figure.figsize']. Users without stylesheets won't notice any difference. |
|
Have to be careful when merging #11266, those two PRs need some alignment. But nothing difficult. |
|
There was always some hesitation of adding global configs in the past but I think this is a useful addition. |
|
Actually... Why don't we also support setting the figsize directly as well? |
Good point! A tuple value could work nicely as a third mode alongside # 1. "computed" — current default, figsize scales with panel count
xr.set_options(facetgrid_figsize="computed")
# 2. "rcparams" — defers to matplotlib global state / stylesheet
# e.g. with a corporate or publication style template:
plt.style.use("acme_corp.mplstyle") # sets figure.figsize: 7.2, 4.5
xr.set_options(facetgrid_figsize="rcparams")
# 3. tuple — fixed figsize scoped to xarray, independent of mpl.rcParams
# useful when you want consistent facet grids without touching global state
xr.set_options(facetgrid_figsize=(12, 6))Let me implement this, and push an update to the pr. |
Add a new `facetgrid_figsize` option to `xr.set_options()` that controls how FacetGrid determines figure size when `figsize` is not explicitly passed. When set to `"rcparams"`, FacetGrid uses `matplotlib.rcParams['figure.figsize']` instead of computing size from `size` and `aspect`. Default is `"computed"` (current behavior). Co-authored-by: Claude <noreply@anthropic.com>
Extend facetgrid_figsize to accept a (width, height) tuple in addition to "computed" and "rcparams". Also move figsize resolution before grid shape computation for better composition with col_wrap="auto" (pydata#11266). Co-authored-by: Claude <noreply@anthropic.com>
87ab727 to
6b1a002
Compare
|
I also looked at the #11266 alignment you mentioned. The figsize from the global option was being resolved after the grid shape computation, so |
There was a problem hiding this comment.
Actually one more thing: can you change bullet point 3 here: https://github.com/pydata/xarray/blob/main/doc%2Fuser-guide%2Foptions.rst to be more general about plotting and add your new option.
Thanks!
Co-authored-by: Claude <noreply@anthropic.com>
5c0a6db to
9e28044
Compare


Summary
facetgrid_figsizeoption toxr.set_options()with two modes:"computed"(default) — current behavior, figure size derived fromsizeandaspect"rcparams"— usematplotlib.rcParams['figure.figsize']as the total figure sizefigsizeparameter still takes precedence over both modescmap_sequential,cmap_divergent)Test plan
ValueError, context manager works for both values"rcparams"mode usesmpl.rcParams, explicitfigsizeoverridestest_options.pysuite passes (21 tests)TestFacetGridclass passes (22 tests)