@@ -65,21 +65,60 @@ def __init__(self, transform, width, height, angle, loc,
65
65
66
66
class AnchoredSizeBar (AnchoredOffsetbox ):
67
67
def __init__ (self , transform , size , label , loc ,
68
- pad = 0.1 , borderpad = 0.1 , sep = 2 , prop = None , frameon = True ,
68
+ pad = 0.1 , borderpad = 0.1 , sep = 2 , prop = None ,
69
+ frameon = True , size_vertical = 0 , color = 'black' ,
70
+ label_top = False ,
69
71
** kwargs ):
70
72
"""
71
73
Draw a horizontal bar with the size in data coordinate of the give axes.
72
74
A label will be drawn underneath (center-aligned).
73
75
74
- pad, borderpad in fraction of the legend font size (or prop)
75
- sep in points.
76
+ Parameters:
77
+ -----------
78
+ transform : matplotlib transformation object
79
+ size : int or float
80
+ horizontal length of the size bar, given in data coordinates
81
+ label : str
82
+ loc : int
83
+ pad : int or float, optional
84
+ in fraction of the legend font size (or prop)
85
+ borderpad : int or float, optional
86
+ in fraction of the legend font size (or prop)
87
+ sep : int or float, optional
88
+ in points
89
+ frameon : bool, optional
90
+ if True, will draw a box around the horizontal bar and label
91
+ size_vertical : int or float, optional
92
+ vertical length of the size bar, given in data coordinates
93
+ color : str, optional
94
+ color for the size bar and label
95
+ label_top : bool, optional
96
+ if true, the label will be over the rectangle
97
+
98
+ Example:
99
+ --------
100
+ >>>> import matplotlib.pyplot as plt
101
+ >>>> import numpy as np
102
+ >>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
103
+ >>>> fig, ax = plt.subplots()
104
+ >>>> ax = imshow(np.random.random((10,10)))
105
+ >>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', pad=0.5, loc=4, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white')
106
+ >>>> ax.add_artist(bar)
107
+ >>>> plt.show()
108
+
76
109
"""
110
+
77
111
self .size_bar = AuxTransformBox (transform )
78
- self .size_bar .add_artist (Rectangle ((0 ,0 ), size , 0 , fc = "none" ))
112
+ self .size_bar .add_artist (Rectangle ((0 ,0 ), size , size_vertical , fill = True , facecolor = color , edgecolor = color ))
79
113
80
114
self .txt_label = TextArea (label , minimumdescent = False )
81
115
82
- self ._box = VPacker (children = [self .size_bar , self .txt_label ],
116
+ if label_top :
117
+ _box_children = [self .txt_label , self .size_bar ]
118
+ else :
119
+ _box_children = [self .size_bar , self .txt_label ]
120
+
121
+ self ._box = VPacker (children = _box_children ,
83
122
align = "center" ,
84
123
pad = 0 , sep = sep )
85
124
0 commit comments