@@ -32,7 +32,7 @@ def draw_text(ax):
3232
3333def draw_circles (ax ):
3434 """Draw circles in axes coordinates."""
35- area = DrawingArea (40 , 20 , 0 , 0 )
35+ area = DrawingArea (width = 40 , height = 20 )
3636 area .add_artist (Circle ((10 , 10 ), 10 , fc = "tab:blue" ))
3737 area .add_artist (Circle ((30 , 10 ), 5 , fc = "tab:red" ))
3838 box = AnchoredOffsetbox (
@@ -48,38 +48,21 @@ def draw_ellipse(ax):
4848 ax .add_artist (box )
4949
5050
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-
7151def draw_sizebar (ax ):
7252 """
7353 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.
7555 """
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.
8366
8467
8568fig , ax = plt .subplots ()
0 commit comments