@@ -71,10 +71,10 @@ class AnchoredSizeBar(AnchoredOffsetbox):
71
71
def __init__ (self , transform , size , label , loc ,
72
72
pad = 0.1 , borderpad = 0.1 , sep = 2 , prop = None ,
73
73
frameon = True , size_vertical = 0 , color = 'black' ,
74
- label_top = False , fontsize = 12 ,
74
+ label_top = False , fontprops = None ,
75
75
** kwargs ):
76
76
"""
77
- Draw a horizontal bar with the size in data coordinate of the give axes.
77
+ Draw a horizontal bar with the size in data coordinate of the given axes.
78
78
A label will be drawn underneath (center-aligned).
79
79
80
80
Parameters:
@@ -98,29 +98,44 @@ def __init__(self, transform, size, label, loc,
98
98
color for the size bar and label
99
99
label_top : bool, optional
100
100
if True, the label will be over the rectangle
101
- fontsize : int, optional
102
- sets the fontsize for the label
101
+ fontprops: a matplotlib.font_manager.FontProperties instance, optional
102
+ sets the font properties for the label text
103
+
104
+ Returns:
105
+ --------
106
+ AnchoredSizeBar object
103
107
104
108
Example:
105
109
--------
106
- >>>> import matplotlib.pyplot as plt
107
- >>>> import numpy as np
108
- >>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
109
- >>>> fig, ax = plt.subplots()
110
- >>>> ax = imshow(np.random.random((10,10)))
111
- >>>> 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', fontsize=20)
112
- >>>> ax.add_artist(bar)
113
- >>>> fig.show()
110
+ >>> import matplotlib.pyplot as plt
111
+ >>> import numpy as np
112
+ >>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
113
+ >>> fig, ax = plt.subplots()
114
+ >>> ax.imshow(np.random.random((10,10)))
115
+ >>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4)
116
+ >>> ax.add_artist(bar)
117
+ >>> fig.show()
118
+
119
+ Using all the optional parameters
120
+
121
+ >>> import matplotlib.font_manager as fm
122
+ >>> fontprops = fm.FontProperties(size=14, family='monospace')
123
+ >>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontprops=fontprops)
114
124
115
125
"""
116
126
117
127
self .size_bar = AuxTransformBox (transform )
118
128
self .size_bar .add_artist (Rectangle ((0 ,0 ), size , size_vertical , fill = True , facecolor = color , edgecolor = color ))
119
129
130
+ if not fontprops :
131
+ textprops = {'color' : color }
132
+ else :
133
+ textprops = {'color' : color , 'fontproperties' : fontprops }
134
+
120
135
self .txt_label = TextArea (
121
136
label ,
122
137
minimumdescent = False ,
123
- textprops = dict ( color = color , fontsize = fontsize ) )
138
+ textprops = textprops )
124
139
125
140
if label_top :
126
141
_box_children = [self .txt_label , self .size_bar ]
0 commit comments