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

Skip to content

Commit abb83b9

Browse files
committed
Revert "Fix problem with (deep)copy of TextPath"
This reverts commit 7c152aa.
1 parent eb8ada2 commit abb83b9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def __deepcopy__(self, memo=None):
276276
codes = self.codes.copy()
277277
except AttributeError:
278278
codes = None
279-
return Path(
279+
return self.__class__(
280280
self.vertices.copy(), codes,
281281
_interpolation_steps=self._interpolation_steps)
282282

lib/matplotlib/textpath.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def __init__(self, xy, s, size=None, prop=None,
381381
size = prop.get_size_in_points()
382382

383383
self._xy = xy
384+
self.set_size(size)
384385

385386
self._cached_vertices = None
386387
s, ismath = Text(usetex=usetex)._preprocess_math(s)
@@ -389,12 +390,11 @@ def __init__(self, xy, s, size=None, prop=None,
389390
_interpolation_steps=_interpolation_steps,
390391
readonly=True)
391392
self._should_simplify = False
392-
self.set_size(size)
393393

394394
def set_size(self, size):
395395
"""Set the text size."""
396396
self._size = size
397-
self._recache_path()
397+
self._invalid = True
398398

399399
def get_size(self):
400400
"""Get the text size."""
@@ -403,8 +403,9 @@ def get_size(self):
403403
@property
404404
def vertices(self):
405405
"""
406-
Return the cached path.
406+
Return the cached path after updating it if necessary.
407407
"""
408+
self._revalidate_path()
408409
return self._cached_vertices
409410

410411
@property
@@ -414,15 +415,17 @@ def codes(self):
414415
"""
415416
return self._codes
416417

417-
def _recache_path(self):
418+
def _revalidate_path(self):
418419
"""
419-
Update the path.
420+
Update the path if necessary.
420421
421-
The path for the text is initially created with the font size of
422+
The path for the text is initially create with the font size of
422423
`.FONT_SCALE`, and this path is rescaled to other size when necessary.
423424
"""
424-
tr = (Affine2D()
425-
.scale(self._size / text_to_path.FONT_SCALE)
426-
.translate(*self._xy))
427-
self._cached_vertices = tr.transform(self._vertices)
428-
self._cached_vertices.flags.writeable = False
425+
if self._invalid or self._cached_vertices is None:
426+
tr = (Affine2D()
427+
.scale(self._size / text_to_path.FONT_SCALE)
428+
.translate(*self._xy))
429+
self._cached_vertices = tr.transform(self._vertices)
430+
self._cached_vertices.flags.writeable = False
431+
self._invalid = False

0 commit comments

Comments
 (0)