Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ENH]: Allow figaspect to use default width rather than default height #21539

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

Open
mitchnegus opened this issue Nov 4, 2021 · 2 comments
Open

Comments

@mitchnegus
Copy link
Contributor

Problem

I was recently working on a long document involving several plots, and I wanted all of them to have a consistent width (thus keeping my title/label font sizes consistent throughout the document). The matploltib.figure.figaspect function does exactly this, except it uses the default figure height (rcParams['figure.figsize'][1]) as the dimension to keep consistent, rather than the width.

I ended up writing my own function to mimic figaspect except to use the default width rather than default height, but it seemed like this capability might be relatively unintrusively added to figaspect.

Proposed solution

My proposed solution is to add a single kwarg to figaspect that toggles whether the default dimension used is width or height. This would be something simple, named like fixed_dim or fixed_dimension, that is set to fixed_dim = 'height' by default (maintaining the current behavior), but allowing fixed_dim = 'width' to use the opposite dimension as the one to keep consistent.

(I'm happy to do the work seeing this change through if it gets support)

Additional context and prior art

Similar ideas were thrown around in #18244, though my impression that most of the consideration there was aimed towards allowing the figure size to scale.

Some of what I see as relevant takeaways from that issue thread (and my responses) seem to be:

  1. Constraining by width seems to be a relatively common (if not the predominant) mode when writing documents with similarly sized figures. Allowing figaspect to use the default width would be a natural way of managing the figure sizes in those circumstances.
  2. Adding kwargs promiscuously should be avoided, especially when those keywords enable mutually exclusive behaviors. Unlike some of the other discussion, a single fixed_dim kwarg would have a narrower scope and likely a simpler, more intuitive impact—no backwards compatibility issues, no "collateral damage" on other matplotlib features (e.g. does not affect the existing figure, figsize schematic; no outside docstrings to be updated), and no interfering behavior among mutually exclusive operations. It would simply swap the current "fix height, adjust width" behavior for a "fix width, adjust height" behavior.
@jklymak
Copy link
Member

jklymak commented Nov 7, 2021

A you note above this has been asked for in the past, and not moved forward on as undesirable API clutter. If you want to set a fixed width, plt.figure(figsize=(w, w*a)) is pretty straight forward.

@mitchnegus
Copy link
Contributor Author

Got it. I thought this was a slightly different approach from what had been proposed before, and might have offered a way to cleanly resolve your point there that widths are often a more natural fixed dimension but without adding too much clutter. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants