Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9101f0

Browse filesBrowse files
document-textpath
1 parent 36bc620 commit e9101f0
Copy full SHA for e9101f0

File tree

Expand file treeCollapse file tree

5 files changed

+94
-19
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+94
-19
lines changed

‎doc/api/api_overview.rst

Copy file name to clipboardExpand all lines: doc/api/api_overview.rst
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Further reading:
3838
- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of
3939
plotting functions.
4040
- Most of the :ref:`examples <examples-index>` use the object-oriented approach
41-
(except for the pyplot section).
41+
(except for the pyplot section)
42+
- The list of :doc:`matplotlib modules </api/index>`.
4243

4344

4445
The pylab API (disapproved)

‎doc/api/index.rst

Copy file name to clipboardExpand all lines: doc/api/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Modules
5555
style_api.rst
5656
table_api.rst
5757
text_api.rst
58+
textpath_api.rst
5859
ticker_api.rst
5960
tight_layout_api.rst
6061
transformations.rst

‎doc/api/textpath_api.rst

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
********
2+
textpath
3+
********
4+
5+
6+
:mod:`matplotlib.textpath`
7+
==========================
8+
9+
.. automodule:: matplotlib.textpath
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:

‎examples/text_labels_and_annotations/demo_text_path.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/demo_text_path.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Demo Text Path
44
==============
55
6+
Use a text as `Path`. The tool that allows for such conversion is a
7+
`~matplotlib.textpath.TextPath`. The resulting path can be employed
8+
e.g. as a clip path for an image.
69
"""
710

811
import matplotlib.pyplot as plt

‎lib/matplotlib/textpath.py

Copy file name to clipboardExpand all lines: lib/matplotlib/textpath.py
+76-18Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
@@ -391,16 +416,49 @@ class TextPath(Path):
391416
def __init__(self, xy, s, size=None, prop=None,
392417
_interpolation_steps=1, usetex=False,
393418
*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)
399460
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`.
404462
"""
405463

406464
if prop is None:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.