def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None, loc=4, pad=0.1, borderpad=0.1, sep=2, prop=None, xorder='text above', textprops=None, linewidth=3, bbox=[1, 1.115, 0, 0], bbox_transform=None, **kwargs): """Draw a horizontal and/or vertical bar with the size in data coordinate of the give axes. A label will be drawn underneath (center-aligned). This is from GitHubGist user dmeliza, with the code found at https://gist.github.com/dmeliza/3251476 Args: transform : the coordinate frame (typically axes.transData) sizex,sizey : width of x,y bar, in data units. 0 to omit labelx,labely : labels for x,y bars; None to omit loc : position in containing axes pad, borderpad : padding, in fraction of the legend font size (or prop) sep : separation between labels and bars in points. **kwargs : additional arguments passed to base class constructor linewidth : Thickness of the scale bar bbox : Where the scale bar should be relative to the axis """ from matplotlib.patches import Rectangle from matplotlib.offsetbox import AuxTransformBox, VPacker, HPacker, TextArea, DrawingArea bars = AuxTransformBox(transform) if sizex: bars.add_artist( Rectangle((0, 0), sizex, 0, fc="none", linewidth=linewidth)) if sizey: bars.add_artist(Rectangle((0, 0), 0, sizey, fc="none"), linewidth=linewidth) if sizex and labelx: text_area = TextArea(labelx, textprops=textprops, minimumdescent=False) if xorder == 'text above': bar_child = [text_area, bars] elif xorder == 'text below': bar_child = [bars, text_area] bars = VPacker(children=bar_child, align="right", pad=0, sep=sep) if sizey and labely: text_area = TextArea(labely, textprops=textprops) bars = HPacker(children=[text_area, bars], align="center", pad=0, sep=sep) AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad, child=bars, prop=prop, frameon=False, bbox_transform=bbox_transform, **kwargs) AnchoredOffsetbox.set_bbox_to_anchor(self, bbox, transform=bbox_transform)