Skip to content

Commit 0f208bb

Browse files
committed
Change anchored_artists.AnchoredSizeBar: docstring, vertical size, color
- Add size_vertical variable, which sets the height of the size bar. - Add color argument, which change the color of rectangle bar (not the label, need to figure out how to do that). - Docstring: listing the possible arguments and adding an example.
1 parent 5e8d808 commit 0f208bb

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

lib/mpl_toolkits/axes_grid1/anchored_artists.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,48 @@ def __init__(self, transform, width, height, angle, loc,
6565

6666
class AnchoredSizeBar(AnchoredOffsetbox):
6767
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',
6970
**kwargs):
7071
"""
7172
Draw a horizontal bar with the size in data coordinate of the give axes.
7273
A label will be drawn underneath (center-aligned).
7374
74-
pad, borderpad in fraction of the legend font size (or prop)
75-
sep in points.
75+
Parameters:
76+
-----------
77+
transform : matplotlib transformation object
78+
size : int or float
79+
horizontal length of the size bar, given in data coordinates
80+
label : str
81+
loc : int
82+
pad : int or float, optional
83+
in fraction of the legend font size (or prop)
84+
borderpad : int or float, optional
85+
in fraction of the legend font size (or prop)
86+
sep : int or float, optional
87+
in points
88+
frameon : bool, optional
89+
if True, will draw a box around the horizontal bar and label
90+
size_vertical : int or float, optional
91+
vertical length of the size bar, given in data coordinates
92+
color : str, optional
93+
color for the size bar and label
94+
95+
Example:
96+
--------
97+
>>>> import matplotlib.pyplot as plt
98+
>>>> import numpy as np
99+
>>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
100+
>>>> fig, ax = plt.subplots()
101+
>>>> ax = imshow(np.random.random((10,10)))
102+
>>>> 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')
103+
>>>> ax.add_artist(bar)
104+
>>>> plt.show()
105+
76106
"""
107+
77108
self.size_bar = AuxTransformBox(transform)
78-
self.size_bar.add_artist(Rectangle((0,0), size, 0, fc="none"))
109+
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))
79110

80111
self.txt_label = TextArea(label, minimumdescent=False)
81112

0 commit comments

Comments
 (0)