@@ -2138,6 +2138,8 @@ def __init__(self,
2138
2138
subplotpars = None , # rc figure.subplot.*
2139
2139
tight_layout = None , # rc figure.autolayout
2140
2140
constrained_layout = None , # rc figure.constrained_layout.use
2141
+ * ,
2142
+ layout = None ,
2141
2143
):
2142
2144
"""
2143
2145
Parameters
@@ -2166,22 +2168,63 @@ def __init__(self,
2166
2168
parameters :rc:`figure.subplot.*` are used.
2167
2169
2168
2170
tight_layout : bool or dict, default: :rc:`figure.autolayout`
2169
- If ``False`` use *subplotpars*. If ``True`` adjust subplot
2170
- parameters using `.tight_layout` with default padding.
2171
- When providing a dict containing the keys ``pad``, ``w_pad``,
2172
- ``h_pad``, and ``rect``, the default `.tight_layout` paddings
2173
- will be overridden.
2171
+ Whether to use the tight layout mechanism. See `.set_tight_layout`.
2172
+
2173
+ .. admonition:: Discouraged
2174
+
2175
+ The use of this parameter is discouraged. Please use
2176
+ ``layout='tight'`` instead for the common case
2177
+ ``tight_layout=True`` and use `.set_tight_layout` otherwise.
2174
2178
2175
2179
constrained_layout : bool, default: :rc:`figure.constrained_layout.use`
2176
- If ``True`` use constrained layout to adjust positioning of plot
2177
- elements. Like ``tight_layout``, but designed to be more
2178
- flexible. See
2179
- :doc:`/tutorials/intermediate/constrainedlayout_guide`
2180
- for examples. (Note: does not work with `add_subplot` or
2181
- `~.pyplot.subplot2grid`.)
2180
+ This is equal to ``layout='constrained'``.
2181
+
2182
+ .. admonition:: Discouraged
2183
+
2184
+ The use of this parameter is discouraged. Please use
2185
+ ``layout='constrained'`` instead.
2186
+
2187
+ layout : {'constrained', 'tight'}, optional
2188
+ The layout mechanism for positioning of plot elements.
2189
+ Supported values:
2190
+
2191
+ - 'constrained': The constrained layout solver usually gives the
2192
+ best layout results and is thus recommended. However, it is
2193
+ computationally expensive and can be slow for complex figures
2194
+ with many elements.
2195
+
2196
+ See :doc:`/tutorials/intermediate/constrainedlayout_guide`
2197
+ for examples.
2198
+
2199
+ - 'tight': Use the tight layout mechanism. This is a relatively
2200
+ simple algorithm, that adjusts the subplot parameters so that
2201
+ decorations like tick labels, axis labels and titles have enough
2202
+ space. See `.Figure.set_tight_layout` for further details.
2203
+
2204
+ If not given, fall back to using the parameters *tight_layout* and
2205
+ *constrained_layout*, including their config defaults
2206
+ :rc:`figure.autolayout` and :rc:`figure.constrained_layout.use`.
2182
2207
"""
2183
2208
super ().__init__ ()
2184
2209
2210
+ if layout is not None :
2211
+ if tight_layout is not None :
2212
+ _api .warn_external (
2213
+ "The Figure parameters 'layout' and 'tight_layout' "
2214
+ "cannot be used together. Please use 'layout' only." )
2215
+ if constrained_layout is not None :
2216
+ _api .warn_external (
2217
+ "The Figure parameters 'layout' and 'constrained_layout' "
2218
+ "cannot be used together. Please use 'layout' only." )
2219
+ if layout == 'constrained' :
2220
+ tight_layout = False
2221
+ constrained_layout = True
2222
+ elif layout == 'tight' :
2223
+ tight_layout = True
2224
+ constrained_layout = False
2225
+ else :
2226
+ raise ValueError (f"Invalid value for 'layout': { layout !r} " )
2227
+
2185
2228
self .callbacks = cbook .CallbackRegistry ()
2186
2229
# Callbacks traditionally associated with the canvas (and exposed with
2187
2230
# a proxy property), but that actually need to be on the figure for
@@ -2344,7 +2387,7 @@ def set_tight_layout(self, tight):
2344
2387
----------
2345
2388
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
2346
2389
If a bool, sets whether to call `.tight_layout` upon drawing.
2347
- If ``None``, use the `` figure.autolayout`` rcparam instead.
2390
+ If ``None``, use :rc:` figure.autolayout` instead.
2348
2391
If a dict, pass it as kwargs to `.tight_layout`, overriding the
2349
2392
default paddings.
2350
2393
"""
0 commit comments