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

Skip to content

Commit 25b463c

Browse files
committed
textpath.py: import texmanager only when required
svn path=/trunk/matplotlib/; revision=7636
1 parent 835c4ac commit 25b463c

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

examples/pylab_examples/demo_text_path.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def draw(self, renderer=None):
5454

5555
if 1:
5656

57+
usetex = plt.rcParams["text.usetex"]
58+
5759
fig = plt.figure(1)
5860

5961
# EXAMPLE 1
@@ -80,8 +82,14 @@ def draw(self, renderer=None):
8082

8183
# another text
8284
from matplotlib.patches import PathPatch
83-
text_path = TextPath((0, 0), r"\mbox{textpath supports mathtext \& \TeX}",
84-
size=20, usetex=True)
85+
if usetex:
86+
r = r"\mbox{textpath supports mathtext \& \TeX}"
87+
else:
88+
r = r"textpath supports mathtext & TeX"
89+
90+
text_path = TextPath((0, 0), r,
91+
size=20, usetex=usetex)
92+
8593
p1 = PathPatch(text_path, ec="w", lw=3, fc="w", alpha=0.9,
8694
transform=IdentityTransform())
8795
p2 = PathPatch(text_path, ec="none", fc="k",
@@ -111,7 +119,6 @@ def draw(self, renderer=None):
111119

112120
arr = np.arange(256).reshape(1,256)/256.
113121

114-
usetex = plt.rcParams["text.usetex"]
115122
if usetex:
116123
s = r"$\displaystyle\left[\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}\right]$!"
117124
else:

lib/matplotlib/textpath.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from matplotlib.mathtext import MathTextParser
1010

1111
import matplotlib.dviread as dviread
12-
from matplotlib.texmanager import TexManager
1312

1413
import numpy as np
1514

@@ -31,6 +30,7 @@ def __init__(self):
3130
from matplotlib.cbook import maxdict
3231
self._ps_fontd = maxdict(50)
3332

33+
self._texmanager = None
3434

3535
def _get_font(self, prop):
3636
"""
@@ -243,6 +243,15 @@ def get_glyphs_mathtext(self, prop, s):
243243
return zip(glyph_ids, xpositions, ypositions, sizes), glyph_map, myrects
244244

245245

246+
def get_texmanager(self):
247+
"""
248+
return the :class:`matplotlib.texmanager.TexManager` instance
249+
"""
250+
if self._texmanager is None:
251+
from matplotlib.texmanager import TexManager
252+
self._texmanager = TexManager()
253+
return self._texmanager
254+
246255

247256
def get_glyphs_tex(self, prop, s):
248257
"""
@@ -251,7 +260,7 @@ def get_glyphs_tex(self, prop, s):
251260

252261
# codes are modstly borrowed from pdf backend.
253262

254-
texmanager = TexManager()
263+
texmanager = self.get_texmanager()
255264

256265
if self.tex_font_map is None:
257266
self.tex_font_map = dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))

0 commit comments

Comments
 (0)