Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf9cd63

Browse files
magnunorpelson
authored andcommitted
Improvements to anchored_artists.AnchoredSizeBar
Fix: color argument was not setting the color of the textlabel Add: setting the font-size through the fontsize argument
1 parent 9e8acb2 commit cf9cd63

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/mpl_toolkits/axes_grid1/anchored_artists.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AnchoredSizeBar(AnchoredOffsetbox):
7171
def __init__(self, transform, size, label, loc,
7272
pad=0.1, borderpad=0.1, sep=2, prop=None,
7373
frameon=True, size_vertical=0, color='black',
74-
label_top=False,
74+
label_top=False, fontsize=12,
7575
**kwargs):
7676
"""
7777
Draw a horizontal bar with the size in data coordinate of the give axes.
@@ -97,7 +97,9 @@ def __init__(self, transform, size, label, loc,
9797
color : str, optional
9898
color for the size bar and label
9999
label_top : bool, optional
100-
if true, the label will be over the rectangle
100+
if True, the label will be over the rectangle
101+
fontsize : int, optional
102+
sets the fontsize for the label
101103
102104
Example:
103105
--------
@@ -106,16 +108,19 @@ def __init__(self, transform, size, label, loc,
106108
>>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
107109
>>>> fig, ax = plt.subplots()
108110
>>>> ax = imshow(np.random.random((10,10)))
109-
>>>> 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')
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)
110112
>>>> ax.add_artist(bar)
111-
>>>> plt.show()
113+
>>>> fig.show()
112114
113115
"""
114116

115117
self.size_bar = AuxTransformBox(transform)
116118
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))
117119

118-
self.txt_label = TextArea(label, minimumdescent=False)
120+
self.txt_label = TextArea(
121+
label,
122+
minimumdescent=False,
123+
textprops=dict(color=color, fontsize=fontsize))
119124

120125
if label_top:
121126
_box_children = [self.txt_label, self.size_bar]

0 commit comments

Comments
 (0)