From 62c88bf4e617d61fd5cb31201ab3c4be8b9dfbb4 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 03:23:52 -0500 Subject: [PATCH 1/9] added aliases for figsize, layout, getters and setters for subplotparams --- lib/matplotlib/figure.py | 135 +++++++++++++++++++++++++++- lib/matplotlib/figure.pyi | 7 ++ lib/matplotlib/tests/test_figure.py | 39 ++++++++ 3 files changed, 180 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 11b42b1e1ac7..e0dfbbb5da87 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -10,6 +10,9 @@ `SubFigure`) with `Figure.add_subfigure` or `Figure.subfigures` methods (provisional API v3.4). +`SubplotParams` + Control the default spacing between subplots. + Figures are typically created using pyplot methods `~.pyplot.figure`, `~.pyplot.subplots`, and `~.pyplot.subplot_mosaic`. @@ -48,7 +51,7 @@ import matplotlib.image as mimage from matplotlib.axes import Axes -from matplotlib.gridspec import GridSpec, SubplotParams +from matplotlib.gridspec import GridSpec from matplotlib.layout_engine import ( ConstrainedLayoutEngine, TightLayoutEngine, LayoutEngine, PlaceHolderLayoutEngine @@ -115,6 +118,71 @@ def __setstate__(self, state): self._counter = itertools.count(next_counter) +class SubplotParams: + """ + A class to hold the parameters for a subplot. + """ + + def __init__(self, left=None, bottom=None, right=None, top=None, + wspace=None, hspace=None): + """ + Defaults are given by :rc:`figure.subplot.[name]`. + + Parameters + ---------- + left : float + The position of the left edge of the subplots, + as a fraction of the figure width. + right : float + The position of the right edge of the subplots, + as a fraction of the figure width. + bottom : float + The position of the bottom edge of the subplots, + as a fraction of the figure height. + top : float + The position of the top edge of the subplots, + as a fraction of the figure height. + wspace : float + The width of the padding between subplots, + as a fraction of the average Axes width. + hspace : float + The height of the padding between subplots, + as a fraction of the average Axes height. + """ + self._validate = True + for key in ["left", "bottom", "right", "top", "wspace", "hspace"]: + setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"]) + self.update(left, bottom, right, top, wspace, hspace) + + # Also remove _validate after deprecation elapses. + validate = _api.deprecate_privatize_attribute("3.5") + + def update(self, left=None, bottom=None, right=None, top=None, + wspace=None, hspace=None): + """ + Update the dimensions of the passed parameters. *None* means unchanged. + """ + if self._validate: + if ((left if left is not None else self.left) + >= (right if right is not None else self.right)): + raise ValueError('left cannot be >= right') + if ((bottom if bottom is not None else self.bottom) + >= (top if top is not None else self.top)): + raise ValueError('bottom cannot be >= top') + if left is not None: + self.left = left + if right is not None: + self.right = right + if bottom is not None: + self.bottom = bottom + if top is not None: + self.top = top + if wspace is not None: + self.wspace = wspace + if hspace is not None: + self.hspace = hspace + + class FigureBase(Artist): """ Base class for `.Figure` and `.SubFigure` containing the methods that add @@ -1277,6 +1345,11 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, hspace : float, optional The height of the padding between subplots, as a fraction of the average Axes height. + + See Also + -------- + matplotlib.figure.Figure.set_subplotparams + matplotlib.figure.Figure.get_subplotparams """ if (self.get_layout_engine() is not None and not self.get_layout_engine().adjust_compatible): @@ -1291,6 +1364,62 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, ax._set_position(ax.get_subplotspec().get_position(self)) self.stale = True + def set_subplotparams(self, subplotparams={}): + """ + Set the subplot layout parameters. + Accepts either a `.SubplotParams` object, from which the relevant + parameters are copied, or a dictionary of subplot layout parameters. + If a dictionary is provided, this function is a convenience wrapper for + `matplotlib.figure.Figure.subplots_adjust` + Parameters + ---------- + subplotparams : `~matplotlib.figure.SubplotParams` or dict with keys \ +"left", "bottom", "right", 'top", "wspace", "hspace"] , optional + SubplotParams object to copy new subplot parameters from, or a dict + of SubplotParams constructor arguments. + By default, an empty dictionary is passed, which maintains the + current state of the figure's `.SubplotParams` + See Also + -------- + matplotlib.figure.Figure.subplots_adjust + matplotlib.figure.Figure.get_subplotparams + """ + subplotparams_args = ["left", "bottom", "right", + "top", "wspace", "hspace"] + kwargs = {} + if isinstance(subplotparams, SubplotParams): + for key in subplotparams_args: + kwargs[key] = getattr(subplotparams, key) + elif isinstance(subplotparams, dict): + for key in subplotparams.keys(): + if key in subplotparams_args: + kwargs[key] = subplotparams[key] + else: + _api.warn_external( + f"'{key}' is not a valid key for set_subplotparams;" + " this key was ignored.") + else: + raise TypeError( + "subplotpars must be a dictionary of keyword-argument pairs or" + " an instance of SubplotParams()") + if kwargs == {}: + self.set_subplotparams(self.get_subplotparams()) + self.subplots_adjust(**kwargs) + + def get_subplotparams(self): + """ + Return the `.SubplotParams` object associated with the Figure. + + Returns + ------- + `.SubplotParams` + See Also + -------- + matplotlib.figure.Figure.subplots_adjust + matplotlib.figure.Figure.get_subplotparams + """ + return self.subplotpars + def align_xlabels(self, axs=None): """ Align the xlabels of subplots in the same subplot column if label @@ -2306,6 +2435,10 @@ def draw(self, renderer): @_docstring.interpd +@_api._define_aliases({ + "size_inches": ["figsize"], + "layout_engine": ["layout"] +}) class Figure(FigureBase): """ The top level container for all the plot elements. diff --git a/lib/matplotlib/figure.pyi b/lib/matplotlib/figure.pyi index 687ae9e500d0..db60555f159e 100644 --- a/lib/matplotlib/figure.pyi +++ b/lib/matplotlib/figure.pyi @@ -244,6 +244,13 @@ class FigureBase(Artist): gridspec_kw: dict[str, Any] | None = ..., ) -> dict[Hashable, Axes]: ... + def set_subplotparams( + self, + subplotparams: SubplotParams | dict[str, Any] = ..., + ) -> None: ... + + def get_subplotparams(self) -> SubplotParams: ... + class SubFigure(FigureBase): figure: Figure subplotpars: SubplotParams diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 99b2602bc4a7..84a785b80937 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1652,6 +1652,45 @@ def test_get_constrained_layout_pads(): assert fig.get_constrained_layout_pads() == expected +def test_get_subplot_params(): + fig = plt.figure() + subplotparams_keys = ["left", "bottom", "right", "top", "wspace", "hspace"] + subplotparams = fig.get_subplotparams() + test_dict = {} + for key in subplotparams_keys: + attr = getattr(subplotparams, key) + assert attr == mpl.rcParams[f"figure.subplot.{key}"] + test_dict[key] = attr * 2 + + fig.set_subplotparams(test_dict) + for key, value in test_dict.items(): + assert getattr(fig.get_subplotparams(), key) == value + + test_dict['foo'] = 'bar' + with pytest.warns(UserWarning, + match="'foo' is not a valid key for set_subplotparams;" + " this key was ignored"): + fig.set_subplotparams(test_dict) + + with pytest.raises(TypeError, + match="subplotparams must be a dictionary of " + "keyword-argument pairs or " + "an instance of SubplotParams()"): + fig.set_subplotparams(['foo']) + + assert fig.subplotpars == fig.get_subplotparams() + + +def test_fig_get_set(): + varnames = filter(lambda var: var not in ['self', 'kwargs', 'args'], + Figure.__init__.__code__.co_varnames) + fig = plt.figure() + for var in varnames: + # if getattr fails then the getter and setter does not exist + getfunc = getattr(fig, f"get_{var}") + setfunc = getattr(fig, f"set_{var}") + + def test_not_visible_figure(): fig = Figure() From 77cace70823d9d5565e77306ab90010b93aa25c7 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 03:31:25 -0500 Subject: [PATCH 2/9] added aliases for figsize, layout, getters and setters for subplotparams --- lib/matplotlib/figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e0dfbbb5da87..3dfb14e6173a 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2435,7 +2435,7 @@ def draw(self, renderer): @_docstring.interpd -@_api._define_aliases({ +@_api.define_aliases({ "size_inches": ["figsize"], "layout_engine": ["layout"] }) From 50239bf423040b2645cf66ec16f35531d84c98bc Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 13:17:23 -0500 Subject: [PATCH 3/9] Addressed errors but renaming stubs and adder/getters --- lib/matplotlib/figure.py | 18 +++++++++--------- lib/matplotlib/figure.pyi | 4 ++-- lib/matplotlib/tests/test_figure.py | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 3dfb14e6173a..529e6302d798 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1348,8 +1348,8 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, See Also -------- - matplotlib.figure.Figure.set_subplotparams - matplotlib.figure.Figure.get_subplotparams + matplotlib.figure.Figure.set_subplotpars + matplotlib.figure.Figure.get_subplotpars """ if (self.get_layout_engine() is not None and not self.get_layout_engine().adjust_compatible): @@ -1364,7 +1364,7 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, ax._set_position(ax.get_subplotspec().get_position(self)) self.stale = True - def set_subplotparams(self, subplotparams={}): + def set_subplotpars(self, subplotparams={}): """ Set the subplot layout parameters. Accepts either a `.SubplotParams` object, from which the relevant @@ -1374,7 +1374,7 @@ def set_subplotparams(self, subplotparams={}): Parameters ---------- subplotparams : `~matplotlib.figure.SubplotParams` or dict with keys \ -"left", "bottom", "right", 'top", "wspace", "hspace"] , optional + "left", "bottom", "right", 'top", "wspace", "hspace"] , optional SubplotParams object to copy new subplot parameters from, or a dict of SubplotParams constructor arguments. By default, an empty dictionary is passed, which maintains the @@ -1382,7 +1382,7 @@ def set_subplotparams(self, subplotparams={}): See Also -------- matplotlib.figure.Figure.subplots_adjust - matplotlib.figure.Figure.get_subplotparams + matplotlib.figure.Figure.get_subplotpars """ subplotparams_args = ["left", "bottom", "right", "top", "wspace", "hspace"] @@ -1396,17 +1396,17 @@ def set_subplotparams(self, subplotparams={}): kwargs[key] = subplotparams[key] else: _api.warn_external( - f"'{key}' is not a valid key for set_subplotparams;" + f"'{key}' is not a valid key for set_subplotpars;" " this key was ignored.") else: raise TypeError( "subplotpars must be a dictionary of keyword-argument pairs or" " an instance of SubplotParams()") if kwargs == {}: - self.set_subplotparams(self.get_subplotparams()) + self.set_subplotpars(self.get_subplotpars()) self.subplots_adjust(**kwargs) - def get_subplotparams(self): + def get_subplotpars(self): """ Return the `.SubplotParams` object associated with the Figure. @@ -1416,7 +1416,7 @@ def get_subplotparams(self): See Also -------- matplotlib.figure.Figure.subplots_adjust - matplotlib.figure.Figure.get_subplotparams + matplotlib.figure.Figure.get_subplotpars """ return self.subplotpars diff --git a/lib/matplotlib/figure.pyi b/lib/matplotlib/figure.pyi index db60555f159e..5dc7e7f2ae1b 100644 --- a/lib/matplotlib/figure.pyi +++ b/lib/matplotlib/figure.pyi @@ -244,12 +244,12 @@ class FigureBase(Artist): gridspec_kw: dict[str, Any] | None = ..., ) -> dict[Hashable, Axes]: ... - def set_subplotparams( + def set_subplotpars( self, subplotparams: SubplotParams | dict[str, Any] = ..., ) -> None: ... - def get_subplotparams(self) -> SubplotParams: ... + def get_subplotpars(self) -> SubplotParams: ... class SubFigure(FigureBase): figure: Figure diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 84a785b80937..1a53716a19d3 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1655,30 +1655,30 @@ def test_get_constrained_layout_pads(): def test_get_subplot_params(): fig = plt.figure() subplotparams_keys = ["left", "bottom", "right", "top", "wspace", "hspace"] - subplotparams = fig.get_subplotparams() + subplotparams = fig.get_subplotpars() test_dict = {} for key in subplotparams_keys: attr = getattr(subplotparams, key) assert attr == mpl.rcParams[f"figure.subplot.{key}"] test_dict[key] = attr * 2 - fig.set_subplotparams(test_dict) + fig.set_subplotpars(test_dict) for key, value in test_dict.items(): - assert getattr(fig.get_subplotparams(), key) == value + assert getattr(fig.get_subplotpars(), key) == value test_dict['foo'] = 'bar' with pytest.warns(UserWarning, - match="'foo' is not a valid key for set_subplotparams;" + match="'foo' is not a valid key for set_subplotpars;" " this key was ignored"): - fig.set_subplotparams(test_dict) + fig.set_subplotpars(test_dict) with pytest.raises(TypeError, - match="subplotparams must be a dictionary of " + match="subplotpars must be a dictionary of " "keyword-argument pairs or " "an instance of SubplotParams()"): - fig.set_subplotparams(['foo']) + fig.set_subplotpars(['foo']) - assert fig.subplotpars == fig.get_subplotparams() + assert fig.subplotpars == fig.get_subplotpars() def test_fig_get_set(): From 573a98d613693778cc1d129ac1da36a3101c472c Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 13:52:46 -0500 Subject: [PATCH 4/9] removed connect from test_get_subplot_params as it is not a param for init for the firgure class --- lib/matplotlib/tests/test_figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 1a53716a19d3..1c6c8b3165e8 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1682,7 +1682,7 @@ def test_get_subplot_params(): def test_fig_get_set(): - varnames = filter(lambda var: var not in ['self', 'kwargs', 'args'], + varnames = filter(lambda var: var not in ['self', 'kwargs', 'args', 'connect'], Figure.__init__.__code__.co_varnames) fig = plt.figure() for var in varnames: From 089c93553af714c652f76b1be920d7fffde66aa6 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 14:38:26 -0500 Subject: [PATCH 5/9] suplotparams class was already implemented, removed it from figure.py --- lib/matplotlib/figure.py | 67 +--------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 529e6302d798..b5f19648c29c 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -51,7 +51,7 @@ import matplotlib.image as mimage from matplotlib.axes import Axes -from matplotlib.gridspec import GridSpec +from matplotlib.gridspec import GridSpec, SubplotParams from matplotlib.layout_engine import ( ConstrainedLayoutEngine, TightLayoutEngine, LayoutEngine, PlaceHolderLayoutEngine @@ -118,71 +118,6 @@ def __setstate__(self, state): self._counter = itertools.count(next_counter) -class SubplotParams: - """ - A class to hold the parameters for a subplot. - """ - - def __init__(self, left=None, bottom=None, right=None, top=None, - wspace=None, hspace=None): - """ - Defaults are given by :rc:`figure.subplot.[name]`. - - Parameters - ---------- - left : float - The position of the left edge of the subplots, - as a fraction of the figure width. - right : float - The position of the right edge of the subplots, - as a fraction of the figure width. - bottom : float - The position of the bottom edge of the subplots, - as a fraction of the figure height. - top : float - The position of the top edge of the subplots, - as a fraction of the figure height. - wspace : float - The width of the padding between subplots, - as a fraction of the average Axes width. - hspace : float - The height of the padding between subplots, - as a fraction of the average Axes height. - """ - self._validate = True - for key in ["left", "bottom", "right", "top", "wspace", "hspace"]: - setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"]) - self.update(left, bottom, right, top, wspace, hspace) - - # Also remove _validate after deprecation elapses. - validate = _api.deprecate_privatize_attribute("3.5") - - def update(self, left=None, bottom=None, right=None, top=None, - wspace=None, hspace=None): - """ - Update the dimensions of the passed parameters. *None* means unchanged. - """ - if self._validate: - if ((left if left is not None else self.left) - >= (right if right is not None else self.right)): - raise ValueError('left cannot be >= right') - if ((bottom if bottom is not None else self.bottom) - >= (top if top is not None else self.top)): - raise ValueError('bottom cannot be >= top') - if left is not None: - self.left = left - if right is not None: - self.right = right - if bottom is not None: - self.bottom = bottom - if top is not None: - self.top = top - if wspace is not None: - self.wspace = wspace - if hspace is not None: - self.hspace = hspace - - class FigureBase(Artist): """ Base class for `.Figure` and `.SubFigure` containing the methods that add From fac1a9081e0f7f746887d002bd116f47dac61469 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 15:56:37 -0500 Subject: [PATCH 6/9] fixed documentation related issues --- lib/matplotlib/figure.py | 10 ++++++---- lib/matplotlib/figure.pyi | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index b5f19648c29c..1ce8003d6c6b 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -51,7 +51,7 @@ import matplotlib.image as mimage from matplotlib.axes import Axes -from matplotlib.gridspec import GridSpec, SubplotParams +from matplotlib.gridspec import GridSpec, SubplotParams as SubplotParams from matplotlib.layout_engine import ( ConstrainedLayoutEngine, TightLayoutEngine, LayoutEngine, PlaceHolderLayoutEngine @@ -1306,14 +1306,16 @@ def set_subplotpars(self, subplotparams={}): parameters are copied, or a dictionary of subplot layout parameters. If a dictionary is provided, this function is a convenience wrapper for `matplotlib.figure.Figure.subplots_adjust` + Parameters ---------- - subplotparams : `~matplotlib.figure.SubplotParams` or dict with keys \ + subplotparams : `~matplotlib.figure.SubplotParams` or dict with keys "left", "bottom", "right", 'top", "wspace", "hspace"] , optional SubplotParams object to copy new subplot parameters from, or a dict - of SubplotParams constructor arguments. + of SubplotParams constructor arguments. By default, an empty dictionary is passed, which maintains the - current state of the figure's `.SubplotParams` + current state of the figure's `.SubplotParams` + See Also -------- matplotlib.figure.Figure.subplots_adjust diff --git a/lib/matplotlib/figure.pyi b/lib/matplotlib/figure.pyi index 5dc7e7f2ae1b..f767614eb011 100644 --- a/lib/matplotlib/figure.pyi +++ b/lib/matplotlib/figure.pyi @@ -28,6 +28,7 @@ from .typing import ColorType, HashableList _T = TypeVar("_T") + class FigureBase(Artist): artists: list[Artist] lines: list[Line2D] From cecde0808125af9fb01f1b5dcb04e65c8fa6a273 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 17:36:04 -0500 Subject: [PATCH 7/9] fixed documentation related issues as they were not addressed in the previous commit --- lib/matplotlib/figure.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 1ce8003d6c6b..2e5d4a8333d8 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1350,6 +1350,7 @@ def get_subplotpars(self): Returns ------- `.SubplotParams` + See Also -------- matplotlib.figure.Figure.subplots_adjust From 1622057eecb366061eeadb63750c639135b5a260 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 18:17:44 -0500 Subject: [PATCH 8/9] fixed documentation related issues as they were not addressed in the previous commit --- lib/matplotlib/figure.py | 67 +++++++++++++++++++++++++++++++++++---- lib/matplotlib/figure.pyi | 27 +++++++++++++++- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 2e5d4a8333d8..d21f6d022c93 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -51,7 +51,7 @@ import matplotlib.image as mimage from matplotlib.axes import Axes -from matplotlib.gridspec import GridSpec, SubplotParams as SubplotParams +from matplotlib.gridspec import GridSpec from matplotlib.layout_engine import ( ConstrainedLayoutEngine, TightLayoutEngine, LayoutEngine, PlaceHolderLayoutEngine @@ -118,6 +118,66 @@ def __setstate__(self, state): self._counter = itertools.count(next_counter) +class SubplotParams: + """ + A class to hold the parameters for a subplot. + """ + + def __init__(self, left=None, bottom=None, right=None, top=None, + wspace=None, hspace=None): + """ + Defaults are given by :rc:`figure.subplot.[name]`. + + Parameters + ---------- + left : float + The position of the left edge of the subplots, + as a fraction of the figure width. + right : float + The position of the right edge of the subplots, + as a fraction of the figure width. + bottom : float + The position of the bottom edge of the subplots, + as a fraction of the figure height. + top : float + The position of the top edge of the subplots, + as a fraction of the figure height. + wspace : float + The width of the padding between subplots, + as a fraction of the average Axes width. + hspace : float + The height of the padding between subplots, + as a fraction of the average Axes height. + """ + for key in ["left", "bottom", "right", "top", "wspace", "hspace"]: + setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"]) + self.update(left, bottom, right, top, wspace, hspace) + + def update(self, left=None, bottom=None, right=None, top=None, + wspace=None, hspace=None): + """ + Update the dimensions of the passed parameters. *None* means unchanged. + """ + if ((left if left is not None else self.left) + >= (right if right is not None else self.right)): + raise ValueError('left cannot be >= right') + if ((bottom if bottom is not None else self.bottom) + >= (top if top is not None else self.top)): + raise ValueError('bottom cannot be >= top') + if left is not None: + self.left = left + if right is not None: + self.right = right + if bottom is not None: + self.bottom = bottom + if top is not None: + self.top = top + if wspace is not None: + self.wspace = wspace + if hspace is not None: + self.hspace = hspace + + class FigureBase(Artist): """ Base class for `.Figure` and `.SubFigure` containing the methods that add @@ -1280,11 +1340,6 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, hspace : float, optional The height of the padding between subplots, as a fraction of the average Axes height. - - See Also - -------- - matplotlib.figure.Figure.set_subplotpars - matplotlib.figure.Figure.get_subplotpars """ if (self.get_layout_engine() is not None and not self.get_layout_engine().adjust_compatible): diff --git a/lib/matplotlib/figure.pyi b/lib/matplotlib/figure.pyi index f767614eb011..733223bde2e6 100644 --- a/lib/matplotlib/figure.pyi +++ b/lib/matplotlib/figure.pyi @@ -16,7 +16,7 @@ from matplotlib.backend_bases import ( from matplotlib.colors import Colormap, Normalize from matplotlib.colorbar import Colorbar from matplotlib.cm import ScalarMappable -from matplotlib.gridspec import GridSpec, SubplotSpec, SubplotParams as SubplotParams +from matplotlib.gridspec import GridSpec, SubplotSpec from matplotlib.image import _ImageBase, FigureImage from matplotlib.layout_engine import LayoutEngine from matplotlib.legend import Legend @@ -28,6 +28,31 @@ from .typing import ColorType, HashableList _T = TypeVar("_T") +class SubplotParams: + def __init__( + self, + left: float | None = ..., + bottom: float | None = ..., + right: float | None = ..., + top: float | None = ..., + wspace: float | None = ..., + hspace: float | None = ..., + ) -> None: ... + left: float + right: float + bottom: float + top: float + wspace: float + hspace: float + def update( + self, + left: float | None = ..., + bottom: float | None = ..., + right: float | None = ..., + top: float | None = ..., + wspace: float | None = ..., + hspace: float | None = ..., + ) -> None: ... class FigureBase(Artist): artists: list[Artist] From 80831c27b0fe3eaa2d444bef2a78205ccd2361a1 Mon Sep 17 00:00:00 2001 From: Zaheer Hashmi Date: Sat, 16 Dec 2023 18:55:55 -0500 Subject: [PATCH 9/9] fixed documentation related issues as they were not addressed in the previous commit --- lib/matplotlib/figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index d21f6d022c93..527ea9bd91d6 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2507,7 +2507,7 @@ def __init__(self, frameon : bool, default: :rc:`figure.frameon` If ``False``, suppress drawing the figure background patch. - subplotpars : `~matplotlib.gridspec.SubplotParams` + subplotpars : `SubplotParams` Subplot parameters. If not given, the default subplot parameters :rc:`figure.subplot.*` are used. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy