@@ -104,22 +104,47 @@ def get_text_width_height_descent(self, s, prop, ismath):
104
104
105
105
def get_text_path (self , prop , s , ismath = False , usetex = False ):
106
106
"""
107
- convert text *s* to path (a tuple of vertices and codes for
107
+ Convert text *s* to path (a tuple of vertices and codes for
108
108
matplotlib.path.Path).
109
109
110
- *prop*
111
- font property
110
+ Parameters
111
+ ----------
112
112
113
- *s*
114
- text to be converted
113
+ prop : `matplotlib.font_manager.FontProperties` instance
114
+ The font properties for the text.
115
115
116
- *usetex*
117
- If True, use matplotlib usetex mode .
116
+ s : str
117
+ The text to be converted .
118
118
119
- *ismath*
120
- If True, use mathtext parser. Effective only if usetex == False.
119
+ usetex : bool, optional
120
+ Whether to use tex rendering. Defaults to `` False`` .
121
121
122
+ ismath : bool, optional
123
+ If True, use mathtext parser. Effective only if
124
+ ``usetex == False``.
122
125
126
+ Returns
127
+ -------
128
+
129
+ verts, codes : tuple of lists
130
+ *verts* is a list of numpy arrays containing the x and y
131
+ coordinates of the vertices. *codes* is a list of path codes.
132
+
133
+ Examples
134
+ --------
135
+
136
+ Create a list of vertices and codes from a text, and create a `Path`
137
+ from those::
138
+
139
+ from matplotlib.path import Path
140
+ from matplotlib.textpath import TextToPath
141
+ from matplotlib.font_manager import FontProperties
142
+
143
+ fp = FontProperties(family="Humor Sans", style="italic")
144
+ verts, codes = TextToPath().get_text_path(fp, "ABC")
145
+ path = Path(verts, codes, closed=False)
146
+
147
+ Also see `TextPath` for a more direct way to create a path from a text.
123
148
"""
124
149
if not usetex :
125
150
if not ismath :
@@ -391,16 +416,49 @@ class TextPath(Path):
391
416
def __init__ (self , xy , s , size = None , prop = None ,
392
417
_interpolation_steps = 1 , usetex = False ,
393
418
* kl , ** kwargs ):
394
- """
395
- Create a path from the text. No support for TeX yet. Note that
396
- it simply is a path, not an artist. You need to use the
397
- PathPatch (or other artists) to draw this path onto the
398
- canvas.
419
+ r"""
420
+ Create a path from the text. Note that it simply is a path,
421
+ not an artist. You need to use the `~.PathPatch` (or other artists)
422
+ to draw this path onto the canvas.
423
+
424
+ Parameters
425
+ ----------
426
+
427
+ xy : tuple or array of two float values
428
+ Position of the text. For no offset, use ``xy=(0, 0)``.
429
+
430
+ s : str
431
+ The text to convert to a path.
432
+
433
+ size : float, optional
434
+ Font size in points. Defaults to the size specified via the font
435
+ properties *prop*.
436
+
437
+ prop : `matplotlib.font_manager.FontProperties`, optional
438
+ Font property. If not provided, will use a default
439
+ ``FontProperties`` with parameters from the
440
+ :ref:`rcParams <matplotlib-rcparams>`.
441
+
442
+ _interpolation_steps : integer, optional
443
+ (Currently ignored)
444
+
445
+ usetex : bool, optional
446
+ Whether to use tex rendering. Defaults to ``False``.
447
+
448
+ Examples
449
+ --------
450
+
451
+ The following creates a path from the string "ABC" with Helvetica
452
+ font face; and another path from the latex fraction 1/2::
453
+
454
+ from matplotlib.textpath import TextPath
455
+ from matplotlib.font_manager import FontProperties
456
+
457
+ fp = FontProperties(family="Helvetica", style="italic")
458
+ path1 = TextPath((12,12), "ABC", size=12, prop=fp)
459
+ path2 = TextPath((0,0), r"$\frac{1}{2}$", size=12, usetex=True)
399
460
400
- xy : position of the text.
401
- s : text
402
- size : font size
403
- prop : font property
461
+ Also see :doc:`/gallery/text_labels_and_annotations/demo_text_path`.
404
462
"""
405
463
406
464
if prop is None :
0 commit comments