@@ -2149,6 +2149,8 @@ def __init__(self,
2149
2149
subplotpars = None , # rc figure.subplot.*
2150
2150
tight_layout = None , # rc figure.autolayout
2151
2151
constrained_layout = None , # rc figure.constrained_layout.use
2152
+ * ,
2153
+ layout = None ,
2152
2154
** kwargs
2153
2155
):
2154
2156
"""
@@ -2178,19 +2180,42 @@ def __init__(self,
2178
2180
parameters :rc:`figure.subplot.*` are used.
2179
2181
2180
2182
tight_layout : bool or dict, default: :rc:`figure.autolayout`
2181
- If ``False`` use *subplotpars*. If ``True`` adjust subplot
2182
- parameters using `.tight_layout` with default padding.
2183
- When providing a dict containing the keys ``pad``, ``w_pad``,
2184
- ``h_pad``, and ``rect``, the default `.tight_layout` paddings
2185
- will be overridden.
2183
+ Whether to use the tight layout mechanism. See `.set_tight_layout`.
2184
+
2185
+ .. admonition:: Discouraged
2186
+
2187
+ The use of this parameter is discouraged. Please use
2188
+ ``layout='tight'`` instead for the common case of
2189
+ ``tight_layout=True`` and use `.set_tight_layout` otherwise.
2186
2190
2187
2191
constrained_layout : bool, default: :rc:`figure.constrained_layout.use`
2188
- If ``True`` use constrained layout to adjust positioning of plot
2189
- elements. Like ``tight_layout``, but designed to be more
2190
- flexible. See
2191
- :doc:`/tutorials/intermediate/constrainedlayout_guide`
2192
- for examples. (Note: does not work with `add_subplot` or
2193
- `~.pyplot.subplot2grid`.)
2192
+ This is equal to ``layout='constrained'``.
2193
+
2194
+ .. admonition:: Discouraged
2195
+
2196
+ The use of this parameter is discouraged. Please use
2197
+ ``layout='constrained'`` instead.
2198
+
2199
+ layout : {'constrained', 'tight'}, optional
2200
+ The layout mechanism for positioning of plot elements.
2201
+ Supported values:
2202
+
2203
+ - 'constrained': The constrained layout solver usually gives the
2204
+ best layout results and is thus recommended. However, it is
2205
+ computationally expensive and can be slow for complex figures
2206
+ with many elements.
2207
+
2208
+ See :doc:`/tutorials/intermediate/constrainedlayout_guide`
2209
+ for examples.
2210
+
2211
+ - 'tight': Use the tight layout mechanism. This is a relatively
2212
+ simple algorithm, that adjusts the subplot parameters so that
2213
+ decorations like tick labels, axis labels and titles have enough
2214
+ space. See `.Figure.set_tight_layout` for further details.
2215
+
2216
+ If not given, fall back to using the parameters *tight_layout* and
2217
+ *constrained_layout*, including their config defaults
2218
+ :rc:`figure.autolayout` and :rc:`figure.constrained_layout.use`.
2194
2219
2195
2220
Other Parameters
2196
2221
----------------
@@ -2200,6 +2225,24 @@ def __init__(self,
2200
2225
"""
2201
2226
super ().__init__ (** kwargs )
2202
2227
2228
+ if layout is not None :
2229
+ if tight_layout is not None :
2230
+ _api .warn_external (
2231
+ "The Figure parameters 'layout' and 'tight_layout' "
2232
+ "cannot be used together. Please use 'layout' only." )
2233
+ if constrained_layout is not None :
2234
+ _api .warn_external (
2235
+ "The Figure parameters 'layout' and 'constrained_layout' "
2236
+ "cannot be used together. Please use 'layout' only." )
2237
+ if layout == 'constrained' :
2238
+ tight_layout = False
2239
+ constrained_layout = True
2240
+ elif layout == 'tight' :
2241
+ tight_layout = True
2242
+ constrained_layout = False
2243
+ else :
2244
+ raise ValueError (f"Invalid value for 'layout': { layout !r} " )
2245
+
2203
2246
self .callbacks = cbook .CallbackRegistry ()
2204
2247
# Callbacks traditionally associated with the canvas (and exposed with
2205
2248
# a proxy property), but that actually need to be on the figure for
@@ -2362,7 +2405,7 @@ def set_tight_layout(self, tight):
2362
2405
----------
2363
2406
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
2364
2407
If a bool, sets whether to call `.tight_layout` upon drawing.
2365
- If ``None``, use the `` figure.autolayout`` rcparam instead.
2408
+ If ``None``, use :rc:` figure.autolayout` instead.
2366
2409
If a dict, pass it as kwargs to `.tight_layout`, overriding the
2367
2410
default paddings.
2368
2411
"""
0 commit comments