Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65158f9

Browse files
authored
Merge pull request #11513 from fredrik-1/doc_text
Changed docstrings in Text
2 parents d4f1f8d + 4059c34 commit 65158f9

File tree

1 file changed

+122
-43
lines changed

1 file changed

+122
-43
lines changed

lib/matplotlib/text.py

Lines changed: 122 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(self,
143143
**kwargs
144144
):
145145
"""
146-
Create a `Text` instance at *x*, *y* with string *text*.
146+
Create a `.Text` instance at *x*, *y* with string *text*.
147147
148148
Valid kwargs are
149149
%(Text)s
@@ -200,7 +200,9 @@ def contains(self, mouseevent):
200200
In the case of text, a hit is true anywhere in the
201201
axis-aligned bounding-box containing the text.
202202
203-
Returns True or False.
203+
Returns
204+
-------
205+
bool : bool
204206
"""
205207
if callable(self._contains):
206208
return self._contains(self, mouseevent)
@@ -430,17 +432,19 @@ def _get_layout(self, renderer):
430432

431433
def set_bbox(self, rectprops):
432434
"""
433-
Draw a bounding box around self. rectprops are any settable
434-
properties for a FancyBboxPatch, e.g., facecolor='red', alpha=0.5.
435-
436-
t.set_bbox(dict(facecolor='red', alpha=0.5))
437-
438-
The default boxstyle is 'square'. The mutation
439-
scale of the FancyBboxPatch is set to the fontsize.
435+
Draw a bounding box around self.
440436
441437
Parameters
442438
----------
443-
rectprops : FancyBboxPatch prop dict
439+
rectprops : dict with properties for `.patches.FancyBboxPatch`
440+
The default boxstyle is 'square'. The mutation
441+
scale of the `.patches.FancyBboxPatch` is set to the fontsize.
442+
443+
Examples
444+
--------
445+
::
446+
447+
t.set_bbox(dict(facecolor='red', alpha=0.5))
444448
"""
445449

446450
if rectprops is not None:
@@ -476,7 +480,8 @@ def set_bbox(self, rectprops):
476480

477481
def get_bbox_patch(self):
478482
"""
479-
Return the bbox Patch, or None if the FancyBboxPatch is not made.
483+
Return the bbox Patch, or None if the `.patches.FancyBboxPatch`
484+
is not made.
480485
"""
481486
return self._bbox_patch
482487

@@ -510,7 +515,8 @@ def update_bbox_position_size(self, renderer):
510515

511516
def _draw_bbox(self, renderer, posx, posy):
512517
"""
513-
Update the location and size of the bbox (FancyBboxPatch), and draw.
518+
Update the location and size of the bbox (`.patches.FancyBboxPatch`),
519+
and draw.
514520
"""
515521

516522
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
@@ -532,11 +538,11 @@ def _update_clip_properties(self):
532538

533539
def set_clip_box(self, clipbox):
534540
"""
535-
Set the artist's clip :class:`~matplotlib.transforms.Bbox`.
541+
Set the artist's clip `~.transforms.Bbox`.
536542
537543
Parameters
538544
----------
539-
clipbox : matplotlib.transforms.Bbox
545+
clipbox : `matplotlib.transforms.Bbox`
540546
"""
541547
super().set_clip_box(clipbox)
542548
self._update_clip_properties()
@@ -545,10 +551,10 @@ def set_clip_path(self, path, transform=None):
545551
"""
546552
Set the artist's clip path, which may be:
547553
548-
* a :class:`~matplotlib.patches.Patch` (or subclass) instance
554+
* a `~matplotlib.patches.Patch` (or subclass) instance
549555
550-
* a :class:`~matplotlib.path.Path` instance, in which case
551-
an optional :class:`~matplotlib.transforms.Transform`
556+
* a `~matplotlib.path.Path` instance, in which case
557+
an optional `~matplotlib.transforms.Transform`
552558
instance may be provided, which will be applied to the
553559
path before using it for clipping.
554560
@@ -558,9 +564,8 @@ def set_clip_path(self, path, transform=None):
558564
rectangle, this method will set the clipping box to the
559565
corresponding rectangle and set the clipping path to *None*.
560566
561-
ACCEPTS: [ (:class:`~matplotlib.path.Path`,
562-
:class:`~matplotlib.transforms.Transform`) |
563-
:class:`~matplotlib.patches.Patch` | None ]
567+
ACCEPTS: { (`.path.Path`, `.transforms.Transform`),
568+
`.patches.Patch`, None }
564569
"""
565570
super().set_clip_path(path, transform)
566571
self._update_clip_properties()
@@ -689,7 +694,7 @@ def _get_wrapped_text(self):
689694
@artist.allow_rasterization
690695
def draw(self, renderer):
691696
"""
692-
Draws the :class:`Text` object to the given *renderer*.
697+
Draws the `.Text` object to the given *renderer*.
693698
"""
694699
if renderer is not None:
695700
self._renderer = renderer
@@ -761,35 +766,77 @@ def get_color(self):
761766
return self._color
762767

763768
def get_fontproperties(self):
764-
"Return the :class:`~font_manager.FontProperties` object"
769+
"Return the `.font_manager.FontProperties` object"
765770
return self._fontproperties
766771

767772
def get_fontfamily(self):
768-
"Return the list of font families used for font lookup"
773+
"""
774+
Return the list of font families used for font lookup
775+
776+
See Also
777+
--------
778+
.font_manager.FontProperties.get_family
779+
"""
769780
return self._fontproperties.get_family()
770781

771782
def get_fontname(self):
772-
"Return the font name as string"
783+
"""
784+
Return the font name as string
785+
786+
See Also
787+
--------
788+
.font_manager.FontProperties.get_name
789+
"""
773790
return self._fontproperties.get_name()
774791

775792
def get_fontstyle(self):
776-
"Return the font style as string"
793+
"""
794+
Return the font style as string
795+
796+
See Also
797+
--------
798+
.font_manager.FontProperties.get_style
799+
"""
777800
return self._fontproperties.get_style()
778801

779802
def get_fontsize(self):
780-
"Return the font size as integer"
803+
"""
804+
Return the font size as integer
805+
806+
See Also
807+
--------
808+
.font_manager.FontProperties.get_size_in_points
809+
"""
781810
return self._fontproperties.get_size_in_points()
782811

783812
def get_fontvariant(self):
784-
"Return the font variant as a string"
813+
"""
814+
Return the font variant as a string
815+
816+
See Also
817+
--------
818+
.font_manager.FontProperties.get_variant
819+
"""
785820
return self._fontproperties.get_variant()
786821

787822
def get_fontweight(self):
788-
"Get the font weight as string or number"
823+
"""
824+
Get the font weight as string or number
825+
826+
See Also
827+
--------
828+
.font_manager.FontProperties.get_weight
829+
"""
789830
return self._fontproperties.get_weight()
790831

791832
def get_stretch(self):
792-
'Get the font stretch as a string or number'
833+
"""
834+
Get the font stretch as a string or number
835+
836+
See Also
837+
--------
838+
.font_manager.FontProperties.get_stretch
839+
"""
793840
return self._fontproperties.get_stretch()
794841

795842
def get_horizontalalignment(self):
@@ -844,7 +891,7 @@ def get_verticalalignment(self):
844891

845892
def get_window_extent(self, renderer=None, dpi=None):
846893
'''
847-
Return a :class:`~matplotlib.transforms.Bbox` object bounding
894+
Return a `~matplotlib.transforms.Bbox` object bounding
848895
the text, in display units.
849896
850897
In addition to being used internally, this is useful for
@@ -853,9 +900,9 @@ def get_window_extent(self, renderer=None, dpi=None):
853900
*renderer* defaults to the _renderer attribute of the text
854901
object. This is not assigned until the first execution of
855902
:meth:`draw`, so you must use this kwarg if you want
856-
to call :meth:`get_window_extent` prior to the first
857-
:meth:`draw`. For getting web page regions, it is
858-
simpler to call the method after saving the figure.
903+
to call `.get_window_extent` prior to the first `draw`. For
904+
getting web page regions, it is simpler to call the method after
905+
saving the figure.
859906
860907
*dpi* defaults to self.figure.dpi; the renderer dpi is
861908
irrelevant. For the web application, if figure.dpi is not
@@ -889,14 +936,13 @@ def set_backgroundcolor(self, color):
889936
"""
890937
Set the background color of the text by updating the bbox.
891938
892-
.. seealso::
893-
894-
:meth:`set_bbox`
895-
To change the position of the bounding box.
896-
897939
Parameters
898940
----------
899941
color : color
942+
943+
See Also
944+
--------
945+
.set_bbox : To change the position of the bounding box
900946
"""
901947
if self._bbox_patch is None:
902948
self.set_bbox(dict(facecolor=color, edgecolor=color))
@@ -946,7 +992,7 @@ def set_multialignment(self, align):
946992
947993
Parameters
948994
----------
949-
align: {'left', 'right', 'center'}
995+
align : {'left', 'right', 'center'}
950996
"""
951997
legal = ('center', 'right', 'left')
952998
if align not in legal:
@@ -978,6 +1024,10 @@ def set_fontfamily(self, fontname):
9781024
----------
9791025
fontname : {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', \
9801026
'monospace'}
1027+
1028+
See Also
1029+
--------
1030+
.font_manager.FontProperties.set_family
9811031
"""
9821032
self._fontproperties.set_family(fontname)
9831033
self.stale = True
@@ -989,6 +1039,10 @@ def set_fontvariant(self, variant):
9891039
Parameters
9901040
----------
9911041
variant : {'normal', 'small-caps'}
1042+
1043+
See Also
1044+
--------
1045+
.font_manager.FontProperties.set_variant
9921046
"""
9931047
self._fontproperties.set_variant(variant)
9941048
self.stale = True
@@ -1000,6 +1054,10 @@ def set_fontstyle(self, fontstyle):
10001054
Parameters
10011055
----------
10021056
fontstyle : {'normal', 'italic', 'oblique'}
1057+
1058+
See Also
1059+
--------
1060+
.font_manager.FontProperties.set_style
10031061
"""
10041062
self._fontproperties.set_style(fontstyle)
10051063
self.stale = True
@@ -1013,6 +1071,10 @@ def set_fontsize(self, fontsize):
10131071
----------
10141072
fontsize : {size in points, 'xx-small', 'x-small', 'small', 'medium', \
10151073
'large', 'x-large', 'xx-large'}
1074+
1075+
See Also
1076+
--------
1077+
.font_manager.FontProperties.set_size
10161078
"""
10171079
self._fontproperties.set_size(fontsize)
10181080
self.stale = True
@@ -1026,6 +1088,10 @@ def set_fontweight(self, weight):
10261088
weight : {a numeric value in range 0-1000, 'ultralight', 'light', \
10271089
'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', \
10281090
'demi', 'bold', 'heavy', 'extra bold', 'black'}
1091+
1092+
See Also
1093+
--------
1094+
.font_manager.FontProperties.set_weight
10291095
"""
10301096
self._fontproperties.set_weight(weight)
10311097
self.stale = True
@@ -1039,6 +1105,10 @@ def set_fontstretch(self, stretch):
10391105
stretch : {a numeric value in range 0-1000, 'ultra-condensed', \
10401106
'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', \
10411107
'expanded', 'extra-expanded', 'ultra-expanded'}
1108+
1109+
See Also
1110+
--------
1111+
.font_manager.FontProperties.set_stretch
10421112
"""
10431113
self._fontproperties.set_stretch(stretch)
10441114
self.stale = True
@@ -1144,12 +1214,11 @@ def is_math_text(s, usetex=None):
11441214

11451215
def set_fontproperties(self, fp):
11461216
"""
1147-
Set the font properties that control the text. *fp* must be a
1148-
:class:`matplotlib.font_manager.FontProperties` object.
1217+
Set the font properties that control the text.
11491218
11501219
Parameters
11511220
----------
1152-
fp : matplotlib.font_manager.FontProperties
1221+
fp : `.font_manager.FontProperties`
11531222
"""
11541223
if isinstance(fp, str):
11551224
fp = FontProperties(fp)
@@ -1184,9 +1253,19 @@ def get_usetex(self):
11841253

11851254
def set_fontname(self, fontname):
11861255
"""
1187-
alias for set_family
1256+
alias for `.set_family`
11881257
11891258
One-way alias only: the getter differs.
1259+
1260+
Parameters
1261+
----------
1262+
fontname : {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', \
1263+
'monospace'}
1264+
1265+
See Also
1266+
--------
1267+
.font_manager.FontProperties.set_family
1268+
11901269
"""
11911270
return self.set_family(fontname)
11921271

0 commit comments

Comments
 (0)