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__" :
@@ -93,8 +78,7 @@ def draw(self, renderer=None):
93
78
else :
94
79
r = r"textpath supports mathtext & TeX"
95
80
96
- text_path = TextPath ((0 , 0 ), r ,
97
- size = 20 , usetex = usetex )
81
+ text_path = TextPath ((0 , 0 ), r , size = 20 , usetex = usetex )
98
82
99
83
p1 = PathPatch (text_path , ec = "w" , lw = 3 , fc = "w" , alpha = 0.9 ,
100
84
transform = IdentityTransform ())
@@ -121,7 +105,7 @@ def draw(self, renderer=None):
121
105
122
106
ax = plt .subplot (212 )
123
107
124
- arr = np .arange (256 ).reshape (1 , 256 )/ 256.
108
+ arr = np .arange (256 ).reshape (1 , 256 ) / 256
125
109
126
110
if usetex :
127
111
s = (r"$\displaystyle\left[\sum_{n=1}^\infty"
@@ -132,10 +116,8 @@ def draw(self, renderer=None):
132
116
text_patch = PathClippedImagePatch (text_path , arr , ec = "none" ,
133
117
transform = IdentityTransform ())
134
118
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" ))
119
+ shadow1 = Shadow (text_patch , 1 , - 1 , props = dict (fc = "none" , ec = "0.6" , lw = 3 ))
120
+ shadow2 = Shadow (text_patch , 1 , - 1 , props = dict (fc = "0.3" , ec = "none" ))
139
121
140
122
# make offset box
141
123
offsetbox = AuxTransformBox (IdentityTransform ())
0 commit comments