8000 Cleanup demo_text_path. · matplotlib/matplotlib@c4da14e · GitHub
[go: up one dir, main page]

Skip to content

Commit c4da14e

Browse files
committed
Cleanup demo_text_path.
1 parent ae93d77 commit c4da14e

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

examples/text_labels_and_annotations/demo_text_path.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@
99
"""
1010

1111
import matplotlib.pyplot as plt
12-
from matplotlib.image import BboxImage
13-
import numpy as np
14-
from matplotlib.transforms import IdentityTransform
15-
16-
import matplotlib.patches as mpatches
17-
18-
from matplotlib.offsetbox import AnnotationBbox,\
19-
AnchoredOffsetbox, AuxTransformBox
20-
2112
from matplotlib.cbook import get_sample_data
22-
13+
from matplotlib.image import BboxImage
14+
from matplotlib.offsetbox import (
15+
AnnotationBbox, AnchoredOffsetbox, AuxTransformBox)
16+
from matplotlib.patches import PathPatch, Shadow
2317
from matplotlib.text import TextPath
18+
from matplotlib.transforms import IdentityTransform
19+
import numpy as np
2420

2521

26-
class PathClippedImagePatch(mpatches.PathPatch):
22+
class PathClippedImagePatch(PathPatch):
2723
"""
2824
The given image is used to draw the face of the patch. Internally,
2925
it uses BboxImage whose clippath set to the path of the patch.
@@ -32,31 +28,20 @@ class PathClippedImagePatch(mpatches.PathPatch):
3228
"""
3329

3430
def __init__(self, path, bbox_image, **kwargs):
35-
mpatches.PathPatch.__init__(self, path, **kwargs)
36-
self._init_bbox_image(bbox_image)
31+
super().__init__(path, **kwargs)
32+
self.bbox_image = BboxImage(
33+
self.get_window_extent, norm=None, origin=None)
34+
self.bbox_image.set_data(bbox_image)
3735

3836
def set_facecolor(self, color):
3937
"""Simply ignore facecolor."""
40-
mpatches.PathPatch.set_facecolor(self, "none")
41-
42-
def _init_bbox_image(self, im):
43-
44-
bbox_image = BboxImage(self.get_window_extent,
45-
norm=None,
46-
origin=None,
47-
)
48-
bbox_image.set_transform(IdentityTransform())
49-
50-
bbox_image.set_data(im)
51-
self.bbox_image = bbox_image
38+
super().set_facecolor("none")
5239

5340
def draw(self, renderer=None):
54-
5541
# the clip path must be updated every draw. any solution? -JJ
5642
self.bbox_image.set_clip_path(self._path, self.get_transform())
5743
self.bbox_image.draw(renderer)
58-
59-
mpatches.PathPatch.draw(self, renderer)
44+
super().draw(renderer)
6045

6146

6247
if __name__ == "__main__":
@@ -132,10 +117,8 @@ def draw(self, renderer=None):
132117
text_patch = PathClippedImagePatch(text_path, arr, ec="none",
133118
transform=IdentityTransform())
134119

135-
shadow1 = mpatches.Shadow(text_patch, 1, -1,
136-
props=dict(fc="none", ec="0.6", lw=3))
137-
shadow2 = mpatches.Shadow(text_patch, 1, -1,
138-
props=dict(fc="0.3", ec="none"))
120+
shadow1 = Shadow(text_patch, 1, -1, props=dict(fc="none", ec="0.6", lw=3))
121+
shadow2 = Shadow(text_patch, 1, -1, props=dict(fc="0.3", ec="none"))
139122

140123
# make offset box
141124
offsetbox = AuxTransformBox(IdentityTransform())

0 commit comments

Comments
 (0)
0