Skip to content

Added rc parameters for tight_layout #12365

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,11 @@ def _validate_linestyle(ls):
'figure.constrained_layout.h_pad': [0.04167, validate_float],
'figure.constrained_layout.w_pad': [0.04167, validate_float],

##Figure tight_layout
'figure.tight_layout.pad': [1.08, validate_float],
'figure.tight_layout.h_pad': [None, validate_float_or_None],
'figure.tight_layout.w_pad': [None, validate_float_or_None],

## Saving figure's properties
'savefig.dpi': ['figure', validate_dpi], # DPI
'savefig.facecolor': ['white', validate_color],
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/tight_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def _get_top(tight_bbox, axes_bbox):

def auto_adjust_subplotpars(
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
ax_bbox_list=None, pad=rcParams['figure.tight_layout.pad'],
h_pad=rcParams['figure.tight_layout.h_pad'], w_pad=rcParams['figure.tight_layout.w_pad'], rect=None):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it's quite uncommon to have the rcParams being evaluated within the function signature. I think this would at least become a problem with the rc_context manager. Better keep the paramers as None and set the values within the function (if param is None: ...).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, this is not just uncommon, but it will not work as expected. The rcParams would be resolved when the function is read from the file but the intent is for them to be resolved when the function is called.

"""
Return a dict of subplot parameters to adjust spacing between subplots.

Expand Down Expand Up @@ -266,7 +267,8 @@ def get_subplotspec_list(axes_list, grid_spec=None):


def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
pad=1.08, h_pad=None, w_pad=None, rect=None):
pad=rcParams['figure.tight_layout.pad'], h_pad=rcParams['figure.tight_layout.h_pad'],
w_pad=rcParams['figure.tight_layout.w_pad'], rect=None):
"""
Return subplot parameters for tight-layouted-figure with specified padding.

Expand Down
3 changes: 3 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@
#figure.autolayout : False ## When True, automatically adjust subplot
## parameters to make the plot fit the figure
## using `tight_layout`
#figure.tight_layout.pad : 1.08 ## padding between the figure edge and subplots
#figure.tight_layout.h_pad : None ## padding height between edges of subplots
#figure.tight_layout.w_pad : None ## padding width between edges of subplots
#figure.constrained_layout.use: False ## When True, automatically make plot
## elements fit on the figure. (Not compatible
## with `autolayout`, above).
Expand Down