From 427abb5c080e717c0619e9b3c19687637c5a3795 Mon Sep 17 00:00:00 2001 From: Abhishek K M <67158080+Sync271@users.noreply.github.com> Date: Sun, 10 Apr 2022 22:50:11 +0530 Subject: [PATCH 1/4] consolidate rect documentation --- lib/matplotlib/_tight_layout.py | 14 ++++++-------- lib/matplotlib/axes/_base.py | 5 ++--- lib/matplotlib/figure.py | 10 ++++------ lib/matplotlib/gridspec.py | 6 ++---- lib/matplotlib/layout_engine.py | 6 ++---- lib/mpl_toolkits/mplot3d/axes3d.py | 4 ++-- 6 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/matplotlib/_tight_layout.py b/lib/matplotlib/_tight_layout.py index 81465f9b5db6..753608cc5d34 100644 --- a/lib/matplotlib/_tight_layout.py +++ b/lib/matplotlib/_tight_layout.py @@ -41,8 +41,8 @@ def _auto_adjust_subplotpars( h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots, as a fraction of the font size. Defaults to *pad*. - rect : tuple[float, float, float, float] - [left, bottom, right, top] in normalized (0, 1) figure coordinates. + rect : tuple + (left, bottom, right, top), default: None. """ rows, cols = shape @@ -183,8 +183,8 @@ def auto_adjust_subplotpars( h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots, as a fraction of the font size. Defaults to *pad*. - rect : tuple[float, float, float, float] - [left, bottom, right, top] in normalized (0, 1) figure coordinates. + rect : tuple + (left, bottom, right, top), default: None. """ nrows, ncols = nrows_ncols span_pairs = [] @@ -262,10 +262,8 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple[float, float, float, float], optional - (left, bottom, right, top) rectangle in normalized figure coordinates - that the whole subplots area (including labels) will fit into. - Defaults to using the entire figure. + rect : tuple + (left, bottom, right, top), default: None. Returns ------- diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index c299fb3b0f94..3353764e07d3 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -582,9 +582,8 @@ def __init__(self, fig, rect, fig : `~matplotlib.figure.Figure` The Axes is built in the `.Figure` *fig*. - rect : [left, bottom, width, height] - The Axes is built in the rectangle *rect*. *rect* is in - `.Figure` coordinates. + rect : tuple + (left, bottom, right, top). sharex, sharey : `~.axes.Axes`, optional The x or y `~.matplotlib.axis` is shared with the x or diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 2e5830ec2463..fc651d5a4eed 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -519,9 +519,8 @@ def add_axes(self, *args, **kwargs): Parameters ---------- - rect : sequence of float - The dimensions [left, bottom, width, height] of the new Axes. All - quantities are in fractions of figure width and height. + rect : tuple + (left, bottom, right, top). projection : {None, 'aitoff', 'hammer', 'lambert', 'mollweide', \ 'polar', 'rectilinear', str}, optional @@ -3240,9 +3239,8 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): h_pad, w_pad : float, default: *pad* Padding (height/width) between edges of adjacent subplots, as a fraction of the font size. - rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1) - A rectangle in normalized figure coordinates into which the whole - subplots area (including labels) will fit. + rect : tuple + (left, bottom, right, top), default: (0, 0, 1, 1). See Also -------- diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index 90d0b57b609b..e9d47dd99c8f 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -460,10 +460,8 @@ def tight_layout(self, figure, renderer=None, h_pad, w_pad : float, optional Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple of 4 floats, default: (0, 0, 1, 1), i.e. the whole figure - (left, bottom, right, top) rectangle in normalized figure - coordinates that the whole subplots area (including labels) will - fit into. + rect : tuple + (left, bottom, right, top), default: None. """ subplotspec_list = _tight_layout.get_subplotspec_list( diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index aeaf44923d66..bde0f121d588 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -123,10 +123,8 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple[float, float, float, float], optional - (left, bottom, right, top) rectangle in normalized figure - coordinates that the subplots (including labels) - will fit into. Defaults to using the entire figure. + rect : tuple + (left, bottom, right, top), default: (0, 0, 1, 1). """ super().__init__(**kwargs) for td in ['pad', 'h_pad', 'w_pad', 'rect']: diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 0b6cc83216d0..e547b3172022 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -64,8 +64,8 @@ def __init__( ---------- fig : Figure The parent figure. - rect : (float, float, float, float) - The ``(left, bottom, width, height)`` axes position. + rect : tuple + (left, bottom, right, top), default: None. elev : float, default: 30 The elevation angle in degrees rotates the camera above and below the x-y plane, with a positive angle corresponding to a location From fafd9c8b996c4a869f9275466d8cf3a2494e3803 Mon Sep 17 00:00:00 2001 From: Abhishek K M <67158080+Sync271@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:37:55 +0530 Subject: [PATCH 2/4] restore explanation --- lib/matplotlib/_tight_layout.py | 6 ++++-- lib/matplotlib/axes/_base.py | 5 +++-- lib/matplotlib/figure.py | 10 ++++++---- lib/matplotlib/gridspec.py | 6 ++++-- lib/matplotlib/layout_engine.py | 5 +++-- lib/mpl_toolkits/mplot3d/axes3d.py | 4 ++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/_tight_layout.py b/lib/matplotlib/_tight_layout.py index 753608cc5d34..055f3fce04e4 100644 --- a/lib/matplotlib/_tight_layout.py +++ b/lib/matplotlib/_tight_layout.py @@ -262,8 +262,10 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple - (left, bottom, right, top), default: None. + rect : tuple (left, bottom, right, top), default: None. + rectangle in normalized figure coordinates + that the whole subplots area (including labels) will fit into. + Defaults to using the entire figure. Returns ------- diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 3353764e07d3..3357efaece78 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -582,8 +582,9 @@ def __init__(self, fig, rect, fig : `~matplotlib.figure.Figure` The Axes is built in the `.Figure` *fig*. - rect : tuple - (left, bottom, right, top). + rect : tuple (left, bottom, width, height). + The Axes is built in the rectangle *rect*. *rect* is in + `.Figure` coordinates. sharex, sharey : `~.axes.Axes`, optional The x or y `~.matplotlib.axis` is shared with the x or diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index fc651d5a4eed..885a31525239 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -519,8 +519,9 @@ def add_axes(self, *args, **kwargs): Parameters ---------- - rect : tuple - (left, bottom, right, top). + rect : tuple (left, bottom, right, top) + The dimensions (left, bottom, right, top) of the new Axes. All + quantities are in fractions of figure width and height. projection : {None, 'aitoff', 'hammer', 'lambert', 'mollweide', \ 'polar', 'rectilinear', str}, optional @@ -3239,8 +3240,9 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): h_pad, w_pad : float, default: *pad* Padding (height/width) between edges of adjacent subplots, as a fraction of the font size. - rect : tuple - (left, bottom, right, top), default: (0, 0, 1, 1). + rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1) + A rectangle in normalized figure coordinates into which the whole + subplots area (including labels) will fit. See Also -------- diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index e9d47dd99c8f..fcf7b8576139 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -460,8 +460,10 @@ def tight_layout(self, figure, renderer=None, h_pad, w_pad : float, optional Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple - (left, bottom, right, top), default: None. + rect : tuple (left, bottom, right, top), default: None. i.e. the whole figure + (left, bottom, right, top) rectangle in normalized figure + coordinates that the whole subplots area (including labels) will + fit into. """ subplotspec_list = _tight_layout.get_subplotspec_list( diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index bde0f121d588..28d88eea9a03 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -123,8 +123,9 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, h_pad, w_pad : float Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple - (left, bottom, right, top), default: (0, 0, 1, 1). + rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1). + rectangle in normalized figure coordinates that the subplots (including labels) + will fit into. """ super().__init__(**kwargs) for td in ['pad', 'h_pad', 'w_pad', 'rect']: diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index e547b3172022..1f59f8d481fd 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -64,8 +64,8 @@ def __init__( ---------- fig : Figure The parent figure. - rect : tuple - (left, bottom, right, top), default: None. + rect : tuple (left, bottom, width, height), default: None. + The ``(left, bottom, width, height)`` axes position. elev : float, default: 30 The elevation angle in degrees rotates the camera above and below the x-y plane, with a positive angle corresponding to a location From 33a792a7e9a40e0e8b8d4a47f94504931dbe7f36 Mon Sep 17 00:00:00 2001 From: Abhishek K M <67158080+Sync271@users.noreply.github.com> Date: Fri, 1 Jul 2022 02:34:26 +0530 Subject: [PATCH 3/4] fix rect definition formatting Co-Authored-By: Jody Klymak --- lib/matplotlib/gridspec.py | 4 ++-- lib/matplotlib/layout_engine.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index fcf7b8576139..bf1e2db11d2c 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -460,10 +460,10 @@ def tight_layout(self, figure, renderer=None, h_pad, w_pad : float, optional Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. - rect : tuple (left, bottom, right, top), default: None. i.e. the whole figure + rect : tuple (left, bottom, right, top), default: None (left, bottom, right, top) rectangle in normalized figure coordinates that the whole subplots area (including labels) will - fit into. + fit into. Default (None) is the whole figure. """ subplotspec_list = _tight_layout.get_subplotspec_list( diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index a5c40c5014cf..e3605ba89cda 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -124,8 +124,8 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1). - rectangle in normalized figure coordinates that the subplots (including labels) - will fit into. + rectangle in normalized figure coordinates that the subplots + (including labels) will fit into. """ super().__init__(**kwargs) for td in ['pad', 'h_pad', 'w_pad', 'rect']: From d9d91301f871d51b8f9e3254819da9a2d43761fa Mon Sep 17 00:00:00 2001 From: Abhishek K M <67158080+Sync271@users.noreply.github.com> Date: Fri, 1 Jul 2022 02:43:55 +0530 Subject: [PATCH 4/4] fix trailing white space and rect definition for `add_axes()` Co-Authored-By: Jody Klymak --- lib/matplotlib/figure.py | 4 ++-- lib/matplotlib/layout_engine.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index c80471fa1717..d277c3045802 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -519,8 +519,8 @@ def add_axes(self, *args, **kwargs): Parameters ---------- - rect : tuple (left, bottom, right, top) - The dimensions (left, bottom, right, top) of the new Axes. All + rect : tuple (left, bottom, width, height) + The dimensions (left, bottom, width, height) of the new Axes. All quantities are in fractions of figure width and height. projection : {None, 'aitoff', 'hammer', 'lambert', 'mollweide', \ diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index e3605ba89cda..f5a25eecae25 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -124,7 +124,7 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1). - rectangle in normalized figure coordinates that the subplots + rectangle in normalized figure coordinates that the subplots (including labels) will fit into. """ super().__init__(**kwargs)