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

Skip to content

Commit aa0bf63

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 bf9a451 commit aa0bf63

File tree

12 files changed

+52
-49
lines changed

12 files changed

+52
-49
lines changed

doc/api/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ Alphabetical list of modules:
149149
testing_api.rst
150150
text_api.rst
151151
texmanager_api.rst
152-
textpath_api.rst
153152
ticker_api.rst
154153
tight_bbox_api.rst
155154
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: 23 additions & 11 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

@@ -525,6 +525,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
525525
The font properties.
526526
angle : float
527527
The rotation angle in degrees anti-clockwise.
528+
ismath : bool or "TeX"
529+
If True, use mathtext parser. If "TeX", use tex for rendering.
528530
mtext : `matplotlib.text.Text`
529531
The original text object to be rendered.
530532
@@ -550,12 +552,18 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
550552
551553
Parameters
552554
----------
553-
prop : `matplotlib.font_manager.FontProperties`
554-
The font property.
555+
x : float
556+
The x location of the text in display coords.
557+
y : float
558+
The y location of the text baseline in display coords.
555559
s : str
556560
The text to be converted.
561+
prop : `matplotlib.font_manager.FontProperties`
562+
The font property.
563+
angle : float
564+
Angle in degrees to render the text at.
557565
ismath : bool or "TeX"
558-
If True, use mathtext parser. If "TeX", use *usetex* mode.
566+
If True, use mathtext parser. If "TeX", use tex for rendering.
559567
"""
560568

561569
text2path = self._text2path
@@ -580,18 +588,22 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
580588

581589
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
582590
"""
583-
Draw the text by converting them to paths using textpath module.
591+
Draw the text by converting them to paths using `.TextToPath`.
584592
585593
Parameters
586594
----------
587-
prop : `matplotlib.font_manager.FontProperties`
588-
The font property.
595+
x : float
596+
The x location of the text in display coords.
597+
y : float
598+
The y location of the text baseline in display coords.
589599
s : str
590600
The text to be converted.
591-
usetex : bool
592-
Whether to use usetex mode.
601+
prop : `matplotlib.font_manager.FontProperties`
602+
The font property.
603+
angle : float
604+
Angle in degrees to render the text at.
593605
ismath : bool or "TeX"
594-
If True, use mathtext parser. If "TeX", use *usetex* mode.
606+
If True, use mathtext parser. If "TeX", use tex for rendering.
595607
"""
596608
path, transform = self._get_text_path_transform(
597609
x, y, s, prop, angle, ismath)

lib/matplotlib/backends/backend_svg.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,18 +1025,6 @@ def _adjust_char_id(self, char_id):
10251025
return char_id.replace("%20", "_")
10261026

10271027
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
1028-
"""
1029-
Draw the text by converting them to paths using the textpath module.
1030-
1031-
Parameters
1032-
----------
1033-
s : str
1034-
text to be converted
1035-
prop : `matplotlib.font_manager.FontProperties`
1036-
font property
1037-
ismath : bool
1038-
If True, use mathtext parser. If "TeX", use *usetex* mode.
1039-
"""
10401028
writer = self.writer
10411029

10421030
writer.comment(s)

lib/matplotlib/markers.py

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

516516
def _set_mathtext_path(self):
517517
"""
518-
Draw mathtext markers '$...$' using TextPath object.
518+
Draw mathtext markers '$...$' using `.TextPath` object.
519519
520520
Submitted by tcb
521521
"""
522-
from matplotlib.textpath import TextPath
522+
from matplotlib.text import TextPath
523523

524524
# again, the properties could be initialised just once outside
525525
# 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 # 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

lib/matplotlib/textpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_text_path(self, prop, s, ismath=False):
9898
from those::
9999
100100
from matplotlib.path import Path
101-
from matplotlib.textpath import TextToPath
101+
from matplotlib.text import TextToPath
102102
from matplotlib.font_manager import FontProperties
103103
104104
fp = FontProperties(family="Humor Sans", style="italic")
@@ -339,7 +339,7 @@ def __init__(self, xy, s, size=None, prop=None,
339339
The following creates a path from the string "ABC" with Helvetica
340340
font face; and another path from the latex fraction 1/2::
341341
342-
from matplotlib.textpath import TextPath
342+
from matplotlib.text import TextPath
343343
from matplotlib.font_manager import FontProperties
344344
345345
fp = FontProperties(family="Helvetica", style="italic")

lib/mpl_toolkits/axes_grid1/anchored_artists.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,26 @@ def __init__(self, transform, label_x, label_y, length=0.15,
340340
back_length : float, default: 0.15
341341
Fraction of the arrow behind the arrow crossing.
342342
head_width : float, default: 10
343-
Width of arrow head, sent to ArrowStyle.
343+
Width of arrow head, sent to `.ArrowStyle`.
344344
head_length : float, default: 15
345-
Length of arrow head, sent to ArrowStyle.
345+
Length of arrow head, sent to `.ArrowStyle`.
346346
tail_width : float, default: 2
347-
Width of arrow tail, sent to ArrowStyle.
347+
Width of arrow tail, sent to `.ArrowStyle`.
348348
text_props, arrow_props : dict
349-
Properties of the text and arrows, passed to
350-
`.textpath.TextPath` and `.patches.FancyArrowPatch`.
349+
Properties of the text and arrows, passed to `.TextPath` and
350+
`.FancyArrowPatch`.
351351
**kwargs
352352
Keyword arguments forwarded to `.AnchoredOffsetbox`.
353353
354354
Attributes
355355
----------
356-
arrow_x, arrow_y : `matplotlib.patches.FancyArrowPatch`
356+
arrow_x, arrow_y : `.FancyArrowPatch`
357357
Arrow x and y
358-
text_path_x, text_path_y : `matplotlib.textpath.TextPath`
358+
text_path_x, text_path_y : `.TextPath`
359359
Path for arrow labels
360-
p_x, p_y : `matplotlib.patches.PathPatch`
360+
p_x, p_y : `.PathPatch`
361361
Patch for arrow labels
362-
box : `matplotlib.offsetbox.AuxTransformBox`
362+
box : `.AuxTransformBox`
363363
Container for the arrows and labels.
364364
365365
Notes

0 commit comments

Comments
 (0)