From 8eacacb8c55b48a3d9188509aab9e5ac8df7d724 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 8 Jan 2022 12:15:42 +0100 Subject: [PATCH 1/2] Started deprecating tight_bbox and tight_layout --- lib/matplotlib/{tight_bbox.py => _tight_bbox.py} | 0 lib/matplotlib/{tight_layout.py => _tight_layout.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename lib/matplotlib/{tight_bbox.py => _tight_bbox.py} (100%) rename lib/matplotlib/{tight_layout.py => _tight_layout.py} (100%) diff --git a/lib/matplotlib/tight_bbox.py b/lib/matplotlib/_tight_bbox.py similarity index 100% rename from lib/matplotlib/tight_bbox.py rename to lib/matplotlib/_tight_bbox.py diff --git a/lib/matplotlib/tight_layout.py b/lib/matplotlib/_tight_layout.py similarity index 100% rename from lib/matplotlib/tight_layout.py rename to lib/matplotlib/_tight_layout.py From 2d8bd625813e4c513bbe8bedddca45da368bca9b Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 8 Jan 2022 12:19:03 +0100 Subject: [PATCH 2/2] Recreated deprecated files and changed references --- doc/api/next_api_changes/deprecations/22134-OG.rst | 5 +++++ doc/api/prev_api_changes/api_changes_1.4.x.rst | 6 +++--- doc/api/prev_api_changes/api_changes_2.2.0.rst | 2 +- doc/api/prev_api_changes/api_changes_3.0.1.rst | 8 ++++---- lib/matplotlib/backend_bases.py | 4 ++-- lib/matplotlib/backends/backend_mixed.py | 2 +- lib/matplotlib/contour.py | 4 ++-- lib/matplotlib/figure.py | 2 +- lib/matplotlib/gridspec.py | 8 ++++---- lib/matplotlib/tight_bbox.py | 5 +++++ lib/matplotlib/tight_layout.py | 5 +++++ 11 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/22134-OG.rst create mode 100644 lib/matplotlib/tight_bbox.py create mode 100644 lib/matplotlib/tight_layout.py diff --git a/doc/api/next_api_changes/deprecations/22134-OG.rst b/doc/api/next_api_changes/deprecations/22134-OG.rst new file mode 100644 index 000000000000..a0f60a843239 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/22134-OG.rst @@ -0,0 +1,5 @@ +Modules ``tight_bbox`` and ``tight_layout`` deprecated +------------------------------------------------------ + +The modules ``matplotlib.tight_bbox`` and ``matplotlib.tight_layout`` are +considered internal and public access is deprecated. \ No newline at end of file diff --git a/doc/api/prev_api_changes/api_changes_1.4.x.rst b/doc/api/prev_api_changes/api_changes_1.4.x.rst index d0952784677c..c90a49fa6512 100644 --- a/doc/api/prev_api_changes/api_changes_1.4.x.rst +++ b/doc/api/prev_api_changes/api_changes_1.4.x.rst @@ -149,9 +149,9 @@ original location: ``drawRect`` from ``FigureCanvasQTAgg``; they were always an implementation detail of the (preserved) ``drawRectangle()`` function. -* The function signatures of `.tight_bbox.adjust_bbox` and - `.tight_bbox.process_figure_for_rasterizing` have been changed. A new - *fixed_dpi* parameter allows for overriding the ``figure.dpi`` setting +* The function signatures of ``matplotlib.tight_bbox.adjust_bbox`` and + ``matplotlib.tight_bbox.process_figure_for_rasterizing`` have been changed. + A new *fixed_dpi* parameter allows for overriding the ``figure.dpi`` setting instead of trying to deduce the intended behaviour from the file format. * Added support for horizontal/vertical axes padding to diff --git a/doc/api/prev_api_changes/api_changes_2.2.0.rst b/doc/api/prev_api_changes/api_changes_2.2.0.rst index 29ed03649fd8..c8a335172edd 100644 --- a/doc/api/prev_api_changes/api_changes_2.2.0.rst +++ b/doc/api/prev_api_changes/api_changes_2.2.0.rst @@ -159,7 +159,7 @@ If `.MovieWriterRegistry` can't find the requested `.MovieWriter`, a more helpful `RuntimeError` message is now raised instead of the previously raised `KeyError`. -`~.tight_layout.auto_adjust_subplotpars` now raises `ValueError` +``matplotlib.tight_layout.auto_adjust_subplotpars`` now raises `ValueError` instead of `RuntimeError` when sizes of input lists don't match diff --git a/doc/api/prev_api_changes/api_changes_3.0.1.rst b/doc/api/prev_api_changes/api_changes_3.0.1.rst index d214ae9e6652..4b203cd04596 100644 --- a/doc/api/prev_api_changes/api_changes_3.0.1.rst +++ b/doc/api/prev_api_changes/api_changes_3.0.1.rst @@ -1,10 +1,10 @@ API Changes for 3.0.1 ===================== -`.tight_layout.auto_adjust_subplotpars` can return ``None`` now if the new -subplotparams will collapse axes to zero width or height. This prevents -``tight_layout`` from being executed. Similarly -`.tight_layout.get_tight_layout_figure` will return None. +``matplotlib.tight_layout.auto_adjust_subplotpars`` can return ``None`` now if +the new subplotparams will collapse axes to zero width or height. +This prevents ``tight_layout`` from being executed. Similarly +``matplotlib.tight_layout.get_tight_layout_figure`` will return None. To improve import (startup) time, private modules are now imported lazily. These modules are no longer available at these locations: diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 541ffcf84db0..2bb397068160 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -44,7 +44,7 @@ import matplotlib as mpl from matplotlib import ( _api, backend_tools as tools, cbook, colors, docstring, textpath, - tight_bbox, transforms, widgets, get_backend, is_interactive, rcParams) + _tight_bbox, transforms, widgets, get_backend, is_interactive, rcParams) from matplotlib._pylab_helpers import Gcf from matplotlib.backend_managers import ToolManager from matplotlib.cbook import _setattr_cm @@ -2248,7 +2248,7 @@ def print_figure( bbox_inches = bbox_inches.padded(pad_inches) # call adjust_bbox to save only the given area - restore_bbox = tight_bbox.adjust_bbox( + restore_bbox = _tight_bbox.adjust_bbox( self.figure, bbox_inches, self.figure.canvas.fixed_dpi) _bbox_inches_restore = (bbox_inches, restore_bbox) diff --git a/lib/matplotlib/backends/backend_mixed.py b/lib/matplotlib/backends/backend_mixed.py index 54ca8f81ba02..593c2bb3c0d8 100644 --- a/lib/matplotlib/backends/backend_mixed.py +++ b/lib/matplotlib/backends/backend_mixed.py @@ -2,7 +2,7 @@ from matplotlib import cbook from matplotlib.backends.backend_agg import RendererAgg -from matplotlib.tight_bbox import process_figure_for_rasterizing +from matplotlib._tight_bbox import process_figure_for_rasterizing class MixedModeRenderer: diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 50f76903cae4..f8d31df05d8a 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -282,7 +282,7 @@ def _get_nth_label_width(self, nth): figure=fig, size=self.labelFontSizeList[nth], fontproperties=self.labelFontProps) - .get_window_extent(mpl.tight_layout.get_renderer(fig)).width) + .get_window_extent(mpl._tight_layout.get_renderer(fig)).width) @_api.deprecated("3.5") def get_label_width(self, lev, fmt, fsize): @@ -292,7 +292,7 @@ def get_label_width(self, lev, fmt, fsize): fig = self.axes.figure width = (text.Text(0, 0, lev, figure=fig, size=fsize, fontproperties=self.labelFontProps) - .get_window_extent(mpl.tight_layout.get_renderer(fig)).width) + .get_window_extent(mpl._tight_layout.get_renderer(fig)).width) width *= 72 / fig.dpi return width diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index fb57acec9f1a..a12afead3d74 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3181,7 +3181,7 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): .pyplot.tight_layout """ from contextlib import nullcontext - from .tight_layout import ( + from ._tight_layout import ( get_subplotspec_list, get_tight_layout_figure) subplotspec_list = get_subplotspec_list(self.axes) if None in subplotspec_list: diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index 2aa59ff22b9f..90d0b57b609b 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -18,7 +18,7 @@ import numpy as np import matplotlib as mpl -from matplotlib import _api, _pylab_helpers, tight_layout, rcParams +from matplotlib import _api, _pylab_helpers, _tight_layout, rcParams from matplotlib.transforms import Bbox _log = logging.getLogger(__name__) @@ -466,7 +466,7 @@ def tight_layout(self, figure, renderer=None, fit into. """ - subplotspec_list = tight_layout.get_subplotspec_list( + subplotspec_list = _tight_layout.get_subplotspec_list( figure.axes, grid_spec=self) if None in subplotspec_list: _api.warn_external("This figure includes Axes that are not " @@ -474,9 +474,9 @@ def tight_layout(self, figure, renderer=None, "might be incorrect.") if renderer is None: - renderer = tight_layout.get_renderer(figure) + renderer = _tight_layout.get_renderer(figure) - kwargs = tight_layout.get_tight_layout_figure( + kwargs = _tight_layout.get_tight_layout_figure( figure, figure.axes, subplotspec_list, renderer, pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) if kwargs: diff --git a/lib/matplotlib/tight_bbox.py b/lib/matplotlib/tight_bbox.py new file mode 100644 index 000000000000..a87add58417f --- /dev/null +++ b/lib/matplotlib/tight_bbox.py @@ -0,0 +1,5 @@ +from matplotlib._tight_bbox import * # noqa: F401, F403 +from matplotlib import _api +_api.warn_deprecated( + "3.6", message="The module %(name)s is deprecated since %(since)s.", + name=f"{__name__}") diff --git a/lib/matplotlib/tight_layout.py b/lib/matplotlib/tight_layout.py new file mode 100644 index 000000000000..3cc7d32e352a --- /dev/null +++ b/lib/matplotlib/tight_layout.py @@ -0,0 +1,5 @@ +from matplotlib._tight_layout import * # noqa: F401, F403 +from matplotlib import _api +_api.warn_deprecated( + "3.6", message="The module %(name)s is deprecated since %(since)s.", + name=f"{__name__}")