@@ -32,7 +32,7 @@ def draw_text(ax):
32
32
33
33
def draw_circles (ax ):
34
34
"""Draw circles in axes coordinates."""
35
- area = DrawingArea (40 , 20 , 0 , 0 )
35
+ area = DrawingArea (width = 40 , height = 20 )
36
36
area .add_artist (Circle ((10 , 10 ), 10 , fc = "tab:blue" ))
37
37
area .add_artist (Circle ((30 , 10 ), 5 , fc = "tab:red" ))
38
38
box = AnchoredOffsetbox (
@@ -48,38 +48,21 @@ def draw_ellipse(ax):
48
48
ax .add_artist (box )
49
49
50
50
51
- class AnchoredSizeBar (AnchoredOffsetbox ):
52
- def __init__ (self , transform , size , label , loc ,
53
- pad = 0.1 , borderpad = 0.1 , sep = 2 , prop = None , frameon = True ):
54
- """
55
- Draw a horizontal bar with the size in data coordinate of the given
56
- axes. A label will be drawn underneath (center-aligned).
57
-
58
- pad, borderpad in fraction of the legend font size (or prop)
59
- sep in points.
60
- """
61
- self .size_bar = AuxTransformBox (transform )
62
- self .size_bar .add_artist (Line2D ([0 , size ], [0 , 0 ], color = "black" ))
63
- self .txt_label = TextArea (label )
64
- self ._box = VPacker (children = [self .size_bar , self .txt_label ],
65
- align = "center" ,
66
- pad = 0 , sep = sep )
67
- super ().__init__ (loc , pad = pad , borderpad = borderpad ,
68
- child = self ._box , prop = prop , frameon = frameon )
69
-
70
-
71
51
def draw_sizebar (ax ):
72
52
"""
73
53
Draw a horizontal bar with length of 0.1 in data coordinates,
74
- with a fixed label underneath.
54
+ with a fixed label center-aligned underneath.
75
55
"""
76
- asb = AnchoredSizeBar (ax .transData ,
77
- 0.1 ,
78
- r"1$^{\prime}$" ,
79
- loc = 'lower center' ,
80
- pad = 0.1 , borderpad = 0.5 , sep = 5 ,
81
- frameon = False )
82
- ax .add_artist (asb )
56
+ size = 0.1
57
+ text = r"1$^{\prime}$"
58
+ sizebar = AuxTransformBox (ax .transData )
59
+ sizebar .add_artist (Line2D ([0 , size ], [0 , 0 ], color = "black" ))
60
+ text = TextArea (text )
61
+ packer = VPacker (
62
+ children = [sizebar , text ], align = "center" , sep = 5 ) # separation in points.
63
+ ax .add_artist (AnchoredOffsetbox (
64
+ child = packer , loc = "lower center" , frameon = False ,
65
+ pad = 0.1 , borderpad = 0.5 )) # paddings relative to the legend fontsize.
83
66
84
67
85
68
fig , ax = plt .subplots ()
0 commit comments