Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dec1e13

Browse files
authored
Merge pull request #22345 from jklymak/mnt-make-layout-deprecations-pending
MNT: make layout deprecations pending
2 parents 989659a + 0170e35 commit dec1e13

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Pending deprecation of layout methods
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The methods `~Figure.set_tight_layout`, `~Figure.set_constrained_layout`,
4+
are discouraged, and now emit a ``PendingDeprecationWarning`` in favor of
5+
explicitly referencing the layout engine via
6+
`figure.set_layout_engine('tight')` and
7+
`figure.set_layout_engine('constrained')`. End users should not see the
8+
warning, but library authors should adjust.
9+
10+
The methods `~Figure.set_constrained_layout_pads` and
11+
`~Figure.get_constrained_layout_pads` are will be deprecated in favor of
12+
``figure.get_layout_engine().set()`` and
13+
``figure.get_layout_engine().get()``, and currently emit a
14+
``PendingDeprecationWarning``.

lib/matplotlib/figure.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,11 +2455,16 @@ def get_tight_layout(self):
24552455
"""Return whether `.tight_layout` is called when drawing."""
24562456
return isinstance(self.get_layout_engine(), TightLayoutEngine)
24572457

2458-
@_api.deprecated("3.6", alternative="set_layout_engine")
2458+
@_api.deprecated("3.6", alternative="set_layout_engine",
2459+
pending=True)
24592460
def set_tight_layout(self, tight):
24602461
"""
24612462
Set whether and how `.tight_layout` is called when drawing.
24622463
2464+
.. admonition:: Discouraged
2465+
2466+
This method is discouraged in favor of `~.set_layout_engine`.
2467+
24632468
Parameters
24642469
----------
24652470
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
@@ -2483,7 +2488,8 @@ def get_constrained_layout(self):
24832488
"""
24842489
return isinstance(self.get_layout_engine(), ConstrainedLayoutEngine)
24852490

2486-
@_api.deprecated("3.6", alternative="set_layout_engine('constrained')")
2491+
@_api.deprecated("3.6", alternative="set_layout_engine('constrained')",
2492+
pending=True)
24872493
def set_constrained_layout(self, constrained):
24882494
"""
24892495
Set whether ``constrained_layout`` is used upon drawing. If None,
@@ -2494,7 +2500,9 @@ def set_constrained_layout(self, constrained):
24942500
overridden. These pads are in inches and default to 3.0/72.0.
24952501
``w_pad`` is the width padding and ``h_pad`` is the height padding.
24962502
2497-
See :doc:`/tutorials/intermediate/constrainedlayout_guide`.
2503+
.. admonition:: Discouraged
2504+
2505+
This method is discouraged in favor of `~.set_layout_engine`.
24982506
24992507
Parameters
25002508
----------
@@ -2509,7 +2517,8 @@ def set_constrained_layout(self, constrained):
25092517
self.stale = True
25102518

25112519
@_api.deprecated(
2512-
"3.6", alternative="figure.get_layout_engine().set()")
2520+
"3.6", alternative="figure.get_layout_engine().set()",
2521+
pending=True)
25132522
def set_constrained_layout_pads(self, **kwargs):
25142523
"""
25152524
Set padding for ``constrained_layout``.
@@ -2541,7 +2550,8 @@ def set_constrained_layout_pads(self, **kwargs):
25412550
if isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
25422551
self.get_layout_engine().set(**kwargs)
25432552

2544-
@_api.deprecated("3.6", alternative="fig.get_layout_engine().get_info()")
2553+
@_api.deprecated("3.6", alternative="fig.get_layout_engine().get()",
2554+
pending=True)
25452555
def get_constrained_layout_pads(self, relative=False):
25462556
"""
25472557
Get padding for ``constrained_layout``.

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
21
import numpy as np
32
import pytest
43

@@ -594,14 +593,14 @@ def test_discouraged_api():
594593
fig, ax = plt.subplots(constrained_layout=True)
595594
fig.draw_without_rendering()
596595

597-
with pytest.warns(MatplotlibDeprecationWarning,
598-
match="was deprecated in Matplotlib 3.6"):
596+
with pytest.warns(PendingDeprecationWarning,
597+
match="will be deprecated"):
599598
fig, ax = plt.subplots()
600599
fig.set_constrained_layout(True)
601600
fig.draw_without_rendering()
602601

603-
with pytest.warns(MatplotlibDeprecationWarning,
604-
match="was deprecated in Matplotlib 3.6"):
602+
with pytest.warns(PendingDeprecationWarning,
603+
match="will be deprecated"):
605604
fig, ax = plt.subplots()
606605
fig.set_constrained_layout({'w_pad': 0.02, 'h_pad': 0.02})
607606
fig.draw_without_rendering()

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import warnings
2-
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
32

43
import numpy as np
54
from numpy.testing import assert_array_equal
@@ -372,8 +371,8 @@ def test_clipped_to_axes():
372371

373372
def test_tight_pads():
374373
fig, ax = plt.subplots()
375-
with pytest.warns(MatplotlibDeprecationWarning,
376-
match='was deprecated in Matplotlib 3.6'):
374+
with pytest.warns(PendingDeprecationWarning,
375+
match='will be deprecated'):
377376
fig.set_tight_layout({'pad': 0.15})
378377
fig.draw_without_rendering()
379378

0 commit comments

Comments
 (0)