1
1
from __future__ import (absolute_import , division , print_function ,
2
2
unicode_literals )
3
3
4
- from matplotlib .externals import six
5
-
4
+ from matplotlib .offsetbox import ( AnchoredOffsetbox , AuxTransformBox ,
5
+ DrawingArea , TextArea , VPacker )
6
6
from matplotlib .patches import Rectangle , Ellipse
7
7
8
- import numpy as np
9
-
10
- from matplotlib .offsetbox import AnchoredOffsetbox , AuxTransformBox , VPacker ,\
11
- TextArea , AnchoredText , DrawingArea , AnnotationBbox
12
-
13
8
14
9
class AnchoredDrawingArea (AnchoredOffsetbox ):
15
10
"""
@@ -23,21 +18,18 @@ def __init__(self, width, height, xdescent, ydescent,
23
18
*width*, *height*, *xdescent*, *ydescent* : the dimensions of the DrawingArea.
24
19
*prop* : font property. This is only used for scaling the paddings.
25
20
"""
26
-
27
21
self .da = DrawingArea (width , height , xdescent , ydescent )
28
22
self .drawing_area = self .da
29
23
30
- super (AnchoredDrawingArea , self ).__init__ (loc , pad = pad , borderpad = borderpad ,
31
- child = self .da ,
32
- prop = None ,
33
- frameon = frameon ,
34
- ** kwargs )
24
+ super (AnchoredDrawingArea , self ).__init__ (
25
+ loc , pad = pad , borderpad = borderpad , child = self .da , prop = None ,
26
+ frameon = frameon , ** kwargs
27
+ )
35
28
36
29
37
30
class AnchoredAuxTransformBox (AnchoredOffsetbox ):
38
31
def __init__ (self , transform , loc ,
10000
39
32
pad = 0.4 , borderpad = 0.5 , prop = None , frameon = True , ** kwargs ):
40
-
41
33
self .drawing_area = AuxTransformBox (transform )
42
34
43
35
AnchoredOffsetbox .__init__ (self , loc , pad = pad , borderpad = borderpad ,
@@ -47,7 +39,6 @@ def __init__(self, transform, loc,
47
39
** kwargs )
48
40
49
41
50
-
51
42
class AnchoredEllipse (AnchoredOffsetbox ):
52
43
def __init__ (self , transform , width , height , angle , loc ,
53
44
pad = 0.1 , borderpad = 0.1 , prop = None , frameon = True , ** kwargs ):
@@ -57,7 +48,7 @@ def __init__(self, transform, width, height, angle, loc,
57
48
pad, borderpad in fraction of the legend font size (or prop)
58
49
"""
59
50
self ._box = AuxTransformBox (transform )
60
- self .ellipse = Ellipse ((0 ,0 ), width , height , angle )
51
+ self .ellipse = Ellipse ((0 , 0 ), width , height , angle )
61
52
self ._box .add_artist (self .ellipse )
62
53
63
54
AnchoredOffsetbox .__init__ (self , loc , pad = pad , borderpad = borderpad ,
@@ -122,7 +113,6 @@ def __init__(self, transform, size, label, loc,
122
113
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontproperties=fontprops)
123
114
124
115
"""
125
-
126
116
self .size_bar = AuxTransformBox (transform )
127
117
self .size_bar .add_artist (Rectangle ((0 , 0 ), size , size_vertical ,
128
118
fill = True , facecolor = color ,
@@ -157,73 +147,3 @@ def __init__(self, transform, size, label, loc,
157
147
child = self ._box ,
158
148
prop = fontproperties ,
159
149
frameon = frameon , ** kwargs )
160
-
161
-
162
- if __name__ == "__main__" :
163
-
164
- import matplotlib .pyplot as plt
165
-
166
- fig = plt .gcf ()
167
- fig .clf ()
168
- ax = plt .subplot (111 )
169
-
170
- offsetbox = AnchoredText ("Test" , loc = 6 , pad = 0.3 ,
171
- borderpad = 0.3 , prop = None )
172
- xy = (0.5 , 0.5 )
173
- ax .plot ([0.5 ], [0.5 ], "xk" )
174
- ab = AnnotationBbox (offsetbox , xy ,
175
- xybox = (1. , .5 ),
176
- xycoords = 'data' ,
177
- boxcoords = ("axes fraction" , "data" ),
178
- arrowprops = dict (arrowstyle = "->" ))
179
- #arrowprops=None)
180
-
181
- ax .add_artist (ab )
182
-
183
-
184
- from matplotlib .patches import Circle
185
- ada = AnchoredDrawingArea (20 , 20 , 0 , 0 ,
186
- loc = 6 , pad = 0.1 , borderpad = 0.3 , frameon = True )
187
- p = Circle ((10 , 10 ), 10 )
188
- ada .da .add_artist (p )
189
-
190
- ab = AnnotationBbox (ada , (0.3 , 0.4 ),
191
- xybox = (1. , 0.4 ),
192
- xycoords = 'data' ,
193
- boxcoords = ("axes fraction" , "data" ),
194
- arrowprops = dict (arrowstyle = "->" ))
195
- #arrowprops=None)
196
-
197
- ax .add_artist (ab )
198
-
199
-
200
- arr = np .arange (100 ).reshape ((10 ,10 ))
201
- im = AnchoredImage (arr ,
202
- loc = 4 ,
203
- pad = 0.5 , borderpad = 0.2 , prop = None , frameon = True ,
204
- zoom = 1 ,
205
- cmap = None ,
206
- norm = None ,
207
- interpolation = None ,
208
- origin = None ,
209
- extent = None ,
210
- filternorm = 1 ,
211
- filterrad = 4.0 ,
212
- resample = False ,
213
- )
214
-
215
- ab = AnnotationBbox (im , (0.5 , 0.5 ),
216
- xybox = (- 10. , 10. ),
217
- xycoords = 'data' ,
218
- boxcoords = "offset points" ,
219
- arrowprops = dict (arrowstyle = "->" ))
220
- #arrowprops=None)
221
-
222
- ax .add_artist (ab )
223
-
224
- ax .set_xlim (0 , 1 )
225
- ax .set_ylim (0 , 1 )
226
-
227
-
228
- plt .draw ()
229
- plt .show ()
0 commit comments