9
9
"""
10
10
11
11
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
-
21
12
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
23
17
from matplotlib .text import TextPath
18
+ from matplotlib .transforms import IdentityTransform
19
+ import numpy as np
24
20
25
21
26
- class PathClippedImagePatch (mpatches . PathPatch ):
22
+ class PathClippedImagePatch (PathPatch ):
27
23
"""
28
24
The given image is used to draw the face of the patch. Internally,
29
25
it uses BboxImage whose clippath set to the path of the patch.
@@ -32,31 +28,20 @@ class PathClippedImagePatch(mpatches.PathPatch):
32
28
"""
33
29
34
30
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 )
37
35
38
36
def set_facecolor (self , color ):
39
37
"""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" )
52
39
53
40
def draw (self , renderer = None ):
54
-
55
41
# the clip path must be updated every draw. any solution? -JJ
56
42
self .bbox_image .set_clip_path (self ._path , self .get_transform ())
57
43
self .bbox_image .draw (renderer )
58
-
59
- mpatches .PathPatch .draw (self , renderer )
44
+ super ().draw (renderer )
60
45
61
46
62
47
if __name__ == "__main__" :
@@ -132,10 +117,8 @@ def draw(self, renderer=None):
132
117
text_patch = PathClippedImagePatch (text_path , arr , ec = "none" ,
133
118
transform = IdentityTransform ())
134
119
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" ))
139
122
140
123
# make offset box
141
124
offsetbox = AuxTransformBox (IdentityTransform ())
0 commit comments