@@ -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,67 @@ 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'} or dict, 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' or dict: Use the tight layout mechanism. This is a
2185
+ relatively simple algorithm, that adjusts the subplot parameters
2186
+ so that decorations like tick labels, axis labels and titles
2187
+ have enough space. See `.Figure.set_tight_layout` for further
2188
+ details.
2189
+
2190
+ If not given, fall back to using the parameters *tight_layout* and
2191
+ *constrained_layout*, including their config defaults
2192
+ :rc:`figure.autolayout` and :rc:`figure.constrained_layout.use`.
2167
2193
"""
2168
2194
super ().__init__ ()
2169
2195
2196
+ if layout is not None :
2197
+ if tight_layout is not None :
2198
+ _api .warn_external (
2199
+ "The Figure parameters 'layout' and 'tight_layout' "
2200
+ "cannot be used together. Please use 'layout' only." )
2201
+ if constrained_layout is not None :
2202
+ _api .warn_external (
2203
+ "The Figure parameters 'layout' and 'constrained_layout' "
2204
+ "cannot be used together. Please use 'layout' only." )
2205
+ if layout == 'constrained' :
2206
+ tight_layout = False
2207
+ constrained_layout = True
2208
+ elif layout == 'tight' :
2209
+ tight_layout = True
2210
+ constrained_layout = False
2211
+ elif isinstance (layout , dict ):
2212
+ tight_layout = layout
2213
+ constrained_layout = False
2214
+ else :
2215
+ raise ValueError (f"Invalid value for 'layout': { layout !r} " )
2216
+
2170
2217
self .callbacks = cbook .CallbackRegistry ()
2171
2218
# Callbacks traditionally associated with the canvas (and exposed with
2172
2219
# a proxy property), but that actually need to be on the figure for
@@ -2330,7 +2377,7 @@ def set_tight_layout(self, tight):
2330
2377
----------
2331
2378
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
2332
2379
If a bool, sets whether to call `.tight_layout` upon drawing.
2333
- If ``None``, use the `` figure.autolayout`` rcparam instead.
2380
+ If ``None``, use :rc:` figure.autolayout` instead.
2334
2381
If a dict, pass it as kwargs to `.tight_layout`, overriding the
2335
2382
default paddings.
2336
2383
"""
0 commit comments