Skip to content

Commit 71a3685

Browse files
committed
Soft deprecate the textpath module (import from text instead)
The textpath module was created in 2009, but the status has been a bit vague with many examples and exisiting code found on the internet importing from text instead. In this PR everything is changed to point at text, although textpath is still available for backwards compatibility.
1 parent a9ba9d5 commit 71a3685

File tree

12 files changed

+51
-49
lines changed

12 files changed

+51
-49
lines changed

doc/api/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ Alphabetical list of modules:
147147
testing_api.rst
148148
text_api.rst
149149
texmanager_api.rst
150-
textpath_api.rst
151150
ticker_api.rst
152151
tight_bbox_api.rst
153152
tight_layout_api.rst

doc/api/text_api.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
``matplotlib.text``
33
*******************
44

5+
.. redirect-from:: /api/textpath_api
6+
57
.. automodule:: matplotlib.text
68
:no-members:
79

@@ -19,3 +21,13 @@
1921
:members:
2022
:undoc-members:
2123
:show-inheritance:
24+
25+
.. autoclass:: matplotlib.text.TextPath
26+
:members:
27+
:undoc-members:
28+
:show-inheritance:
29+
30+
.. autoclass:: matplotlib.text.TextToPath
31+
:members:
32+
:undoc-members:
33+
:show-inheritance:

doc/api/textpath_api.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/lines_bars_and_markers/multivariate_marker_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import matplotlib.pyplot as plt
1414
from matplotlib.markers import MarkerStyle
1515
from matplotlib.transforms import Affine2D
16-
from matplotlib.textpath import TextPath
16+
from matplotlib.text import TextPath
1717
from matplotlib.colors import Normalize
1818

1919
SUCCESS_SYMBOLS = [

examples/misc/logos2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import matplotlib.cm as cm
1212
import matplotlib.font_manager
1313
from matplotlib.patches import Rectangle, PathPatch
14-
from matplotlib.textpath import TextPath
14+
from matplotlib.text import TextPath
1515
import matplotlib.transforms as mtrans
1616

1717
MPL_BLUE = '#11557c'

examples/text_labels_and_annotations/demo_text_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Using a text as a Path
44
======================
55
6-
`~matplotlib.textpath.TextPath` creates a `.Path` that is the outline of the
6+
`~matplotlib.text.TextPath` creates a `.Path` that is the outline of the
77
characters of a text. The resulting path can be employed e.g. as a clip path
88
for an image.
99
"""

lib/matplotlib/backend_bases.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import matplotlib as mpl
4545
from matplotlib import (
46-
_api, backend_tools as tools, cbook, colors, _docstring, textpath,
46+
_api, backend_tools as tools, cbook, colors, _docstring, text,
4747
_tight_bbox, transforms, widgets, get_backend, is_interactive, rcParams)
4848
from matplotlib._pylab_helpers import Gcf
4949
from matplotlib.backend_managers import ToolManager
@@ -172,7 +172,7 @@ class RendererBase:
172172
def __init__(self):
173173
super().__init__()
174174
self._texmanager = None
175-
self._text2path = textpath.TextToPath()
175+
self._text2path = text.TextToPath()
176176
self._raster_depth = 0
177177
self._rasterizing = False
178178

@@ -515,7 +515,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
515515
The y location of the text baseline in display coords.
516516
s : str
517517
The TeX text string.
518-
prop : `matplotlib.font_manager.FontProperties`
518+
prop : `~matplotlib.font_manager.FontProperties`
519519
The font properties.
520520
angle : float
521521
The rotation angle in degrees anti-clockwise.
@@ -538,12 +538,12 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
538538
The y location of the text baseline in display coords.
539539
s : str
540540
The text string.
541-
prop : `matplotlib.font_manager.FontProperties`
541+
prop : `~matplotlib.font_manager.FontProperties`
542542
The font properties.
543543
angle : float
544544
The rotation angle in degrees anti-clockwise.
545545
ismath : bool or "TeX"
546-
If True, use mathtext parser. If "TeX", use *usetex* mode.
546+
If True, use mathtext parser. If "TeX", use tex for rendering.
547547
mtext : `matplotlib.text.Text`
548548
The original text object to be rendered.
549549
@@ -569,12 +569,18 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
569569
570570
Parameters
571571
----------
572-
prop : `matplotlib.font_manager.FontProperties`
573-
The font property.
572+
x : float
573+
The x location of the text in display coords.
574+
y : float
575+
The y location of the text baseline in display coords.
574576
s : str
575577
The text to be converted.
578+
prop : `~matplotlib.font_manager.FontProperties`
579+
The font property.
580+
angle : float
581+
Angle in degrees to render the text at.
576582
ismath : bool or "TeX"
577-
If True, use mathtext parser. If "TeX", use *usetex* mode.
583+
If True, use mathtext parser. If "TeX", use tex for rendering.
578584
"""
579585

580586
text2path = self._text2path
@@ -599,18 +605,22 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
599605

600606
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
601607
"""
602-
Draw the text by converting them to paths using textpath module.
608+
Draw the text by converting them to paths using `.TextToPath`.
603609
604610
Parameters
605611
----------
606-
prop : `matplotlib.font_manager.FontProperties`
607-
The font property.
612+
x : float
613+
The x location of the text in display coords.
614+
y : float
615+
The y location of the text baseline in display coords.
608616
s : str
609617
The text to be converted.
610-
usetex : bool
611-
Whether to use usetex mode.
618+
prop : `~matplotlib.font_manager.FontProperties`
619+
The font property.
620+
angle : float
621+
Angle in degrees to render the text at.
612622
ismath : bool or "TeX"
613-
If True, use mathtext parser. If "TeX", use *usetex* mode.
623+
If True, use mathtext parser. If "TeX", use tex for rendering.
614624
"""
615625
path, transform = self._get_text_path_transform(
616626
x, y, s, prop, angle, ismath)

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,18 +1050,7 @@ def _adjust_char_id(self, char_id):
10501050
return char_id.replace("%20", "_")
10511051

10521052
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
1053-
"""
1054-
Draw the text by converting them to paths using the textpath module.
1055-
1056-
Parameters
1057-
----------
1058-
s : str
1059-
text to be converted
1060-
prop : `matplotlib.font_manager.FontProperties`
1061-
font property
1062-
ismath : bool
1063-
If True, use mathtext parser. If "TeX", use *usetex* mode.
1064-
"""
1053+
# docstring inherited
10651054
writer = self.writer
10661055

10671056
writer.comment(s)

lib/matplotlib/markers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ def _set_tuple_marker(self):
516516

517517
def _set_mathtext_path(self):
518518
"""
519-
Draw mathtext markers '$...$' using TextPath object.
519+
Draw mathtext markers '$...$' using `.TextPath` object.
520520
521521
Submitted by tcb
522522
"""
523-
from matplotlib.textpath import TextPath
523+
from matplotlib.text import TextPath
524524

525525
# again, the properties could be initialised just once outside
526526
# this function

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .artist import Artist
1616
from .font_manager import FontProperties
1717
from .patches import FancyArrowPatch, FancyBboxPatch, Rectangle
18-
from .textpath import TextPath # noqa # Unused, but imported by others.
18+
from .textpath import TextPath, TextToPath # Logically located here
1919
from .transforms import (
2020
Affine2D, Bbox, BboxBase, BboxTransformTo, IdentityTransform, Transform)
2121

0 commit comments

Comments
 (0)