Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Show and correct default alignment parameters in text.py #27346

Merged
merged 9 commits into from
Dec 13, 2023
7 changes: 4 additions & 3 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def set_horizontalalignment(self, align):

Parameters
----------
align : {'left', 'center', 'right'}
align : {'left', 'center', 'right'}, default: left
Copy link
Contributor

@StefRe StefRe Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no default value here as the align parameter is not optional (i.e. you can't call set_horizontalalignment() and expect that it sets the alignement to left)

Copy link
Contributor Author

@jsalsman jsalsman Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you don't call the setter, the value is left. How to convey that in the docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default values are (implicitly) documented in the __init__ method (class signature).

Further, matplotlib follows numpydoc conventions:

When a parameter can only assume one of a fixed set of values, those values can be listed in braces, with the default appearing first:

order : {'C', 'F', 'A'}
   Description of `order`.

So the explicit description of the default value is not required in this case, we'd just need to move the baseline entry for verticalalignment to the first position.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the baseline entry for verticalalignment to the first position.

Done.

"""
_api.check_in_list(['center', 'right', 'left'], align=align)
self._horizontalalignment = align
Expand Down Expand Up @@ -1251,7 +1251,8 @@ def set_verticalalignment(self, align):

Parameters
----------
align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}
align : {'bottom', 'baseline', 'center', 'center_baseline', 'top'}, \
default: baseline
"""
Copy link
Contributor

@StefRe StefRe Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above: there is no default value here as the align parameter is not optional.

_api.check_in_list(
['top', 'bottom', 'center', 'baseline', 'center_baseline'],
Expand Down