From 7fd4bb5df69364ac2f3fe0216bb7fd7653b0f279 Mon Sep 17 00:00:00 2001 From: James Salsman Date: Sun, 19 Nov 2023 02:52:26 -0800 Subject: [PATCH 1/9] Show and correct default alignment parameters in text.py For issue [Doc]: text alignment defaults #27345 --- lib/matplotlib/text.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 6371e03603d6..9a6a2c6fe746 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -123,7 +123,7 @@ def __init__(self, The text is aligned relative to the anchor point (*x*, *y*) according to ``horizontalalignment`` (default: 'left') and ``verticalalignment`` - (default: 'bottom'). See also + (default: 'baseline'). See also :doc:`/gallery/text_labels_and_annotations/text_alignment`. While Text accepts the 'label' keyword argument, by default it is not @@ -1002,7 +1002,7 @@ def set_horizontalalignment(self, align): Parameters ---------- - align : {'left', 'center', 'right'} + align : {'left', 'center', 'right'}, default: left """ _api.check_in_list(['center', 'right', 'left'], align=align) self._horizontalalignment = align @@ -1251,7 +1251,7 @@ def set_verticalalignment(self, align): Parameters ---------- - align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'} + align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, default: baseline """ _api.check_in_list( ['top', 'bottom', 'center', 'baseline', 'center_baseline'], From b4461ba4bcc492ff51143aab40ebd5bc8d57e2ef Mon Sep 17 00:00:00 2001 From: James Salsman Date: Sun, 19 Nov 2023 03:03:16 -0800 Subject: [PATCH 2/9] Update text.py: line too long --- lib/matplotlib/text.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 9a6a2c6fe746..ff2a67349037 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1251,7 +1251,8 @@ def set_verticalalignment(self, align): Parameters ---------- - align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, default: baseline + align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, \ +default: baseline """ _api.check_in_list( ['top', 'bottom', 'center', 'baseline', 'center_baseline'], From 5c1708958007737c3569328e357ff6275ebbb46b Mon Sep 17 00:00:00 2001 From: James Salsman Date: Sun, 19 Nov 2023 03:20:18 -0800 Subject: [PATCH 3/9] Show defaults in text_alignment.py --- .../examples/text_labels_and_annotations/text_alignment.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/galleries/examples/text_labels_and_annotations/text_alignment.py b/galleries/examples/text_labels_and_annotations/text_alignment.py index 7ad0d07c6572..4c0351e0bbc5 100644 --- a/galleries/examples/text_labels_and_annotations/text_alignment.py +++ b/galleries/examples/text_labels_and_annotations/text_alignment.py @@ -4,7 +4,8 @@ ============== Texts are aligned relative to their anchor point depending on the properties -``horizontalalignment`` and ``verticalalignment``. +``horizontalalignment`` (default: ``left``) and ``verticalalignment`` +(default: ``baseline``.) .. redirect-from:: /gallery/pyplots/text_layout From 1b4f3e1d38c0bd1521bf307386cbfaee514d97f1 Mon Sep 17 00:00:00 2001 From: James Salsman Date: Wed, 22 Nov 2023 00:12:13 -0800 Subject: [PATCH 4/9] Make setter method defaults match new docstrings in text.py See https://github.com/matplotlib/matplotlib/pull/27346#pullrequestreview-1742239150 --- lib/matplotlib/text.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index ff2a67349037..70e89bdf2113 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -994,7 +994,7 @@ def set_color(self, color): self._color = color self.stale = True - def set_horizontalalignment(self, align): + def set_horizontalalignment(self, align="left"): """ Set the horizontal alignment relative to the anchor point. @@ -1002,7 +1002,7 @@ def set_horizontalalignment(self, align): Parameters ---------- - align : {'left', 'center', 'right'}, default: left + align : {'left', 'center', 'right'}, default: 'left' """ _api.check_in_list(['center', 'right', 'left'], align=align) self._horizontalalignment = align @@ -1243,7 +1243,7 @@ def set_transform_rotates_text(self, t): self._transform_rotates_text = t self.stale = True - def set_verticalalignment(self, align): + def set_verticalalignment(self, align="baseline"): """ Set the vertical alignment relative to the anchor point. @@ -1252,7 +1252,7 @@ def set_verticalalignment(self, align): Parameters ---------- align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, \ -default: baseline +default: 'baseline' """ _api.check_in_list( ['top', 'bottom', 'center', 'baseline', 'center_baseline'], From 1f217b1fd9533addfa6b85cc43712d11b1d87fc9 Mon Sep 17 00:00:00 2001 From: James Salsman Date: Wed, 22 Nov 2023 07:02:33 -0800 Subject: [PATCH 5/9] IDL text alignment set_ method defaults for text.pyi --- lib/matplotlib/text.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/text.pyi b/lib/matplotlib/text.pyi index 6a83b1bbbed9..fb2c958314e8 100644 --- a/lib/matplotlib/text.pyi +++ b/lib/matplotlib/text.pyi @@ -75,7 +75,7 @@ class Text(Artist): def set_backgroundcolor(self, color: ColorType) -> None: ... def set_color(self, color: ColorType) -> None: ... def set_horizontalalignment( - self, align: Literal["left", "center", "right"] + self, align: Literal["left", "center", "right"] = "left" ) -> None: ... def set_multialignment(self, align: Literal["left", "center", "right"]) -> None: ... def set_linespacing(self, spacing: float) -> None: ... @@ -96,6 +96,7 @@ class Text(Artist): def set_transform_rotates_text(self, t: bool) -> None: ... def set_verticalalignment( self, align: Literal["bottom", "baseline", "center", "center_baseline", "top"] + = "baseline" ) -> None: ... def set_text(self, s: Any) -> None: ... def set_fontproperties(self, fp: FontProperties | str | Path | None) -> None: ... From 9784f01b15ba6c04bd1f8650dcf3f262018d9f1e Mon Sep 17 00:00:00 2001 From: James Salsman Date: Wed, 22 Nov 2023 20:22:57 -0800 Subject: [PATCH 6/9] revert interface defaults in text.pyi --- lib/matplotlib/text.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/text.pyi b/lib/matplotlib/text.pyi index fb2c958314e8..6a83b1bbbed9 100644 --- a/lib/matplotlib/text.pyi +++ b/lib/matplotlib/text.pyi @@ -75,7 +75,7 @@ class Text(Artist): def set_backgroundcolor(self, color: ColorType) -> None: ... def set_color(self, color: ColorType) -> None: ... def set_horizontalalignment( - self, align: Literal["left", "center", "right"] = "left" + self, align: Literal["left", "center", "right"] ) -> None: ... def set_multialignment(self, align: Literal["left", "center", "right"]) -> None: ... def set_linespacing(self, spacing: float) -> None: ... @@ -96,7 +96,6 @@ class Text(Artist): def set_transform_rotates_text(self, t: bool) -> None: ... def set_verticalalignment( self, align: Literal["bottom", "baseline", "center", "center_baseline", "top"] - = "baseline" ) -> None: ... def set_text(self, s: Any) -> None: ... def set_fontproperties(self, fp: FontProperties | str | Path | None) -> None: ... From c3949bf94b532ffe808c7018eb3760c9d917ea00 Mon Sep 17 00:00:00 2001 From: James Salsman Date: Wed, 22 Nov 2023 20:29:05 -0800 Subject: [PATCH 7/9] revert defaults in alignment set_ methods text.py did change the order of allowed arguments for set_verticalalignment per @StefRe --- lib/matplotlib/text.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 70e89bdf2113..8734131dddc9 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -994,7 +994,7 @@ def set_color(self, color): self._color = color self.stale = True - def set_horizontalalignment(self, align="left"): + def set_horizontalalignment(self, align): """ Set the horizontal alignment relative to the anchor point. @@ -1002,7 +1002,7 @@ def set_horizontalalignment(self, align="left"): Parameters ---------- - align : {'left', 'center', 'right'}, default: 'left' + align : {'left', 'center', 'right'} """ _api.check_in_list(['center', 'right', 'left'], align=align) self._horizontalalignment = align @@ -1243,7 +1243,7 @@ def set_transform_rotates_text(self, t): self._transform_rotates_text = t self.stale = True - def set_verticalalignment(self, align="baseline"): + def set_verticalalignment(self, align): """ Set the vertical alignment relative to the anchor point. @@ -1251,8 +1251,7 @@ def set_verticalalignment(self, align="baseline"): Parameters ---------- - align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, \ -default: 'baseline' + align : {'baseline', 'bottom', 'center', 'center_baseline', 'top'} """ _api.check_in_list( ['top', 'bottom', 'center', 'baseline', 'center_baseline'], From 59500418f9b0af5f35a63d12021e3d8ea8272403 Mon Sep 17 00:00:00 2001 From: James Salsman Date: Thu, 23 Nov 2023 00:02:23 -0800 Subject: [PATCH 8/9] Document text alignment defaults in _axes.py Because this is where the header at https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.text.html comes from. --- lib/matplotlib/axes/_axes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 2136ecb2eb94..91771999f8d8 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -632,7 +632,10 @@ def text(self, x, y, s, fontdict=None, **kwargs): """ Add text to the Axes. - Add the text *s* to the Axes at location *x*, *y* in data coordinates. + Add the text *s* to the Axes at location *x*, *y* in data coordinates, + with a default ``horizontalalignment`` on the ``left`` and + ``verticalalignment`` at the ``baseline``. See + :doc:`/gallery/text_labels_and_annotations/text_alignment`. Parameters ---------- From 446a3bad607c8c9aeaefa87e21b270856c26ca7e Mon Sep 17 00:00:00 2001 From: James Salsman Date: Thu, 23 Nov 2023 00:06:06 -0800 Subject: [PATCH 9/9] rm trailing whitespace in _axes.py --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 91771999f8d8..d07c5103a202 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -633,7 +633,7 @@ def text(self, x, y, s, fontdict=None, **kwargs): Add text to the Axes. Add the text *s* to the Axes at location *x*, *y* in data coordinates, - with a default ``horizontalalignment`` on the ``left`` and + with a default ``horizontalalignment`` on the ``left`` and ``verticalalignment`` at the ``baseline``. See :doc:`/gallery/text_labels_and_annotations/text_alignment`.