Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MNT: make layout deprecations pending#22345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletionsdoc/api/next_api_changes/deprecations/22345-JK.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
Pending deprecation of layout methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The methods `~Figure.set_tight_layout`, `~Figure.set_constrained_layout`,
are discouraged, and now emit a ``PendingDeprecationWarning`` in favor of
explicitly referencing the layout engine via
`figure.set_layout_engine('tight')` and
`figure.set_layout_engine('constrained')`. End users should not see the
warning, but library authors should adjust.

The methods `~Figure.set_constrained_layout_pads` and
`~Figure.get_constrained_layout_pads` are will be deprecated in favor of
``figure.get_layout_engine().set()`` and
``figure.get_layout_engine().get()``, and currently emit a
``PendingDeprecationWarning``.
20 changes: 15 additions & 5 deletionslib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2484,11 +2484,16 @@ def get_tight_layout(self):
"""Return whether `.tight_layout` is called when drawing."""
return isinstance(self.get_layout_engine(), TightLayoutEngine)

@_api.deprecated("3.6", alternative="set_layout_engine")
@_api.deprecated("3.6", alternative="set_layout_engine",
pending=True)
def set_tight_layout(self, tight):
"""
Set whether and how `.tight_layout` is called when drawing.

.. admonition:: Discouraged

This method is discouraged in favor of `~.set_layout_engine`.

Parameters
----------
tight : bool or dict with keys "pad", "w_pad", "h_pad", "rect" or None
Expand All@@ -2512,7 +2517,8 @@ def get_constrained_layout(self):
"""
return isinstance(self.get_layout_engine(), ConstrainedLayoutEngine)

@_api.deprecated("3.6", alternative="set_layout_engine('constrained')")
@_api.deprecated("3.6", alternative="set_layout_engine('constrained')",
pending=True)
def set_constrained_layout(self, constrained):
"""
Set whether ``constrained_layout`` is used upon drawing. If None,
Expand All@@ -2523,7 +2529,9 @@ def set_constrained_layout(self, constrained):
overridden. These pads are in inches and default to 3.0/72.0.
``w_pad`` is the width padding and ``h_pad`` is the height padding.

See :doc:`/tutorials/intermediate/constrainedlayout_guide`.
.. admonition:: Discouraged

This method is discouraged in favor of `~.set_layout_engine`.

Parameters
----------
Expand All@@ -2538,7 +2546,8 @@ def set_constrained_layout(self, constrained):
self.stale = True

@_api.deprecated(
"3.6", alternative="figure.get_layout_engine().set()")
"3.6", alternative="figure.get_layout_engine().set()",
pending=True)
def set_constrained_layout_pads(self, **kwargs):
"""
Set padding for ``constrained_layout``.
Expand DownExpand Up@@ -2570,7 +2579,8 @@ def set_constrained_layout_pads(self, **kwargs):
if isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
self.get_layout_engine().set(**kwargs)

@_api.deprecated("3.6", alternative="fig.get_layout_engine().get_info()")
@_api.deprecated("3.6", alternative="fig.get_layout_engine().get()",
pending=True)
def get_constrained_layout_pads(self, relative=False):
"""
Get padding for ``constrained_layout``.
Expand Down
9 changes: 4 additions & 5 deletionslib/matplotlib/tests/test_constrainedlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
import numpy as np
import pytest

Expand DownExpand Up@@ -594,14 +593,14 @@ def test_discouraged_api():
fig, ax = plt.subplots(constrained_layout=True)
fig.draw_without_rendering()

with pytest.warns(MatplotlibDeprecationWarning,
match="was deprecated in Matplotlib 3.6"):
with pytest.warns(PendingDeprecationWarning,
match="will be deprecated"):
fig, ax = plt.subplots()
fig.set_constrained_layout(True)
fig.draw_without_rendering()

with pytest.warns(MatplotlibDeprecationWarning,
match="was deprecated in Matplotlib 3.6"):
with pytest.warns(PendingDeprecationWarning,
match="will be deprecated"):
fig, ax = plt.subplots()
fig.set_constrained_layout({'w_pad': 0.02, 'h_pad': 0.02})
fig.draw_without_rendering()
Expand Down
5 changes: 2 additions & 3 deletionslib/matplotlib/tests/test_tightlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
import warnings
from matplotlib._api.deprecation import MatplotlibDeprecationWarning

import numpy as np
from numpy.testing import assert_array_equal
Expand DownExpand Up@@ -372,8 +371,8 @@ def test_clipped_to_axes():

def test_tight_pads():
fig, ax = plt.subplots()
with pytest.warns(MatplotlibDeprecationWarning,
match='was deprecated in Matplotlib 3.6'):
with pytest.warns(PendingDeprecationWarning,
match='will be deprecated'):
fig.set_tight_layout({'pad': 0.15})
fig.draw_without_rendering()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp