@@ -104,22 +104,47 @@ def get_text_width_height_descent(self, s, prop, ismath):
104104
105105 def get_text_path (self , prop , s , ismath = False , usetex = False ):
106106 """
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
108108 matplotlib.path.Path).
109109
110- *prop*
111- font property
110+ Parameters
111+ ----------
112112
113- *s*
114- text to be converted
113+ prop : `matplotlib.font_manager.FontProperties` instance
114+ The font properties for the text.
115115
116- *usetex*
117- If True, use matplotlib usetex mode .
116+ s : str
117+ The text to be converted .
118118
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`` .
121121
122+ ismath : bool, optional
123+ If True, use mathtext parser. Effective only if
124+ ``usetex == False``.
122125
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.
123148 """
124149 if not usetex :
125150 if not ismath :
@@ -392,16 +417,49 @@ class TextPath(Path):
392417 def __init__ (self , xy , s , size = None , prop = None ,
393418 _interpolation_steps = 1 , usetex = False ,
394419 * kl , ** kwargs ):
395- """
396- Create a path from the text. No support for TeX yet. Note that
397- it simply is a path, not an artist. You need to use the
398- PathPatch (or other artists) to draw this path onto the
399- canvas.
420+ r"""
421+ Create a path from the text. Note that it simply is a path,
422+ not an artist. You need to use the `~.PathPatch` (or other artists)
423+ to draw this path onto the canvas.
424+
425+ Parameters
426+ ----------
427+
428+ xy : tuple or array of two float values
429+ Position of the text. For no offset, use ``xy=(0, 0)``.
430+
431+ s : str
432+ The text to convert to a path.
433+
434+ size : float, optional
435+ Font size in points. Defaults to the size specified via the font
436+ properties *prop*.
437+
438+ prop : `matplotlib.font_manager.FontProperties`, optional
439+ Font property. If not provided, will use a default
440+ ``FontProperties`` with parameters from the
441+ :ref:`rcParams <matplotlib-rcparams>`.
442+
443+ _interpolation_steps : integer, optional
444+ (Currently ignored)
445+
446+ usetex : bool, optional
447+ Whether to use tex rendering. Defaults to ``False``.
448+
449+ Examples
450+ --------
451+
452+ The following creates a path from the string "ABC" with Helvetica
453+ font face; and another path from the latex fraction 1/2::
454+
455+ from matplotlib.textpath import TextPath
456+ from matplotlib.font_manager import FontProperties
457+
458+ fp = FontProperties(family="Helvetica", style="italic")
459+ path1 = TextPath((12,12), "ABC", size=12, prop=fp)
460+ path2 = TextPath((0,0), r"$\frac{1}{2}$", size=12, usetex=True)
400461
401- xy : position of the text.
402- s : text
403- size : font size
404- prop : font property
462+ Also see :doc:`/gallery/text_labels_and_annotations/demo_text_path`.
405463 """
406464
407465 if prop is None :
0 commit comments