@@ -2123,6 +2123,8 @@ def __init__(self,
2123
2123
subplotpars = None , # rc figure.subplot.*
2124
2124
tight_layout = None , # rc figure.autolayout
2125
2125
constrained_layout = None , # rc figure.constrained_layout.use
2126
+ * ,
2127
+ layout = None ,
2126
2128
):
2127
2129
"""
2128
2130
Parameters
@@ -2151,22 +2153,63 @@ def __init__(self,
2151
2153
parameters :rc:`figure.subplot.*` are used.
2152
2154
2153
2155
tight_layout : bool or dict, default: :rc:`figure.autolayout`
2154
- If ``False`` use *subplotpars*. If ``True`` adjust subplot
2155
- parameters using `.tight_layout` with default padding.
2156
- When providing a dict containing the keys ``pad``, ``w_pad``,
2157
- ``h_pad``, and ``rect``, the default `.tight_layout` paddings
2158
- will be overridden.
2156
+ This is equal to ``layout='tight'`` or ``layout=dict(...)``.
2157
+
2158
+ .. admonition:: Discouraged
2159
+
2160
+ The use of this parameter is discouraged. Please use
2161
+ ``layout='tight'`` or ``layout=dict(...)`` instead.
2159
2162
2160
2163
constrained_layout : bool, default: :rc:`figure.constrained_layout.use`
2161
- If ``True`` use constrained layout to adjust positioning of plot
2162
- elements. Like ``tight_layout``, but designed to be more
2163
- flexible. See
2164
- :doc:`/tutorials/intermediate/constrainedlayout_guide`
2165
- for examples. (Note: does not work with `add_subplot` or
2166
- `~.pyplot.subplot2grid`.)
2164
+ This is equal to ``layout='constrained'``.
2165
+
2166
+ .. admonition:: Discouraged
2167
+
2168
+ The use of this parameter is discouraged. Please use
2169
+ ``layout='constrained'`` instead.
2170
+
2171
+ layout : {'constrained', 'tight'}, optional
2172
+ The layout mechanism for positioning of plot elements.
2173
+ Supported values:
2174
+
2175
+ - 'constrained': The constrained layout solver usually gives the
2176
+ best layout results and is thus recommended. However, it is
2177
+ computationally expensive and can be slow for complex figures
2178
+ with many elements.
2179
+
2180
+ See :doc:`/tutorials/intermediate/constrainedlayout_guide`
2181
+ for examples. (Note: does not work with `add_subplot` or
2182
+ `~.pyplot.subplot2grid`.)
2183
+
2184
+ - 'tight': Use the tight layout mechanism. This is a relatively
2185
+ simple algorithm, that adjusts the subplot parameters so that
2186
+ decorations like tick labels, axis labels and titles have enough
2187
+ space. See `.Figure.set_tight_layout` for further details.
2188
+
2189
+ If not given, fall back to using the parameters *tight_layout* and
2190
+ *constrained_layout*, including their config defaults
2191
+ :rc:`figure.autolayout` and :rc:`figure.constrained_layout.use`.
2167
2192
"""
2168
2193
super ().__init__ ()
2169
2194
2195
+ if layout is not None :
2196
+ if tight_layout is not None :
2197
+ _api .warn_external (
2198
+ "The Figure parameters 'layout' and 'tight_layout' "
2199
+ "cannot be used together. Please use 'layout' only." )
2200
+ if constrained_layout is not None :
2201
+ _api .warn_external (
2202
+ "The Figure parameters 'layout' and 'constrained_layout' "
2203
+ "cannot be used together. Please use 'layout' only." )
2204
+ if layout == 'constrained' :
2205
+ tight_layout = False
2206
+ constrained_layout = True
2207
+ elif layout == 'tight' :
2208
+ tight_layout = True
2209
+ constrained_layout = False
2210
+ else :
2211
+ raise ValueError (f"Invalid value for 'layout': { layout !r} " )
2212
+
2170
2213
self .callbacks = cbook .CallbackRegistry ()
2171
2214
# Callbacks traditionally associated with the canvas (and exposed with
2172
2215
# a proxy property), but that actually need to be on the figure for
@@ -2330,7 +2373,7 @@ def set_tight_layout(self, tight):
2330
2373
----------
2331
2374
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
2332
2375
If a bool, sets whether to call `.tight_layout` upon drawing.
2333
- If ``None``, use the `` figure.autolayout`` rcparam instead.
2376
+ If ``None``, use :rc:` figure.autolayout` instead.
2334
2377
If a dict, pass it as kwargs to `.tight_layout`, overriding the
2335
2378
default paddings.
2336
2379
"""
0 commit comments