You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
The text was updated successfully, but these errors were encountered:
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.
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!
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 tofigaspect
.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 likefixed_dim
orfixed_dimension
, that is set tofixed_dim = 'height'
by default (maintaining the current behavior), but allowingfixed_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:
figaspect
to use the default width would be a natural way of managing the figure sizes in those circumstances.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 existingfigure
,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.The text was updated successfully, but these errors were encountered: