diff --git a/doc/users/whats_new/anchoredsizebar_fill_bar_argument.rst b/doc/users/whats_new/anchoredsizebar_fill_bar_argument.rst new file mode 100644 index 000000000000..7426f2b25978 --- /dev/null +++ b/doc/users/whats_new/anchoredsizebar_fill_bar_argument.rst @@ -0,0 +1,13 @@ +Add fill_bar argument to ``AnchoredSizeBar`` +-------------------------------------------- + +The mpl_toolkits class +:class:`~mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar` now has an +additional ``fill_bar`` argument, which makes the size bar a solid rectangle +instead of just drawing the border of the rectangle. The default is ``None``, +and whether or not the bar will be filled by default depends on the value of +``size_vertical``. If ``size_vertical`` is nonzero, ``fill_bar`` will be set to +``True``. If ``size_vertical`` is zero then ``fill_bar`` will be set to +``False``. If you wish to override this default behavior, set ``fill_bar`` to +``True`` or ``False`` to unconditionally always or never use a filled patch +rectangle for the size bar. diff --git a/lib/mpl_toolkits/axes_grid1/anchored_artists.py b/lib/mpl_toolkits/axes_grid1/anchored_artists.py index ac5eaf29039e..3cda87108377 100644 --- a/lib/mpl_toolkits/axes_grid1/anchored_artists.py +++ b/lib/mpl_toolkits/axes_grid1/anchored_artists.py @@ -232,7 +232,7 @@ class AnchoredSizeBar(AnchoredOffsetbox): def __init__(self, transform, size, label, loc, pad=0.1, borderpad=0.1, sep=2, frameon=True, size_vertical=0, color='black', - label_top=False, fontproperties=None, + label_top=False, fontproperties=None, fill_bar=None, **kwargs): """ Draw a horizontal scale bar with a center-aligned label underneath. @@ -295,6 +295,12 @@ def __init__(self, transform, size, label, loc, fontproperties : `matplotlib.font_manager.FontProperties`, optional Font properties for the label text. + fill_bar : bool, optional + If True and if size_vertical is nonzero, the size bar will + be filled in with the color specified by the size bar. + Defaults to True if `size_vertical` is greater than + zero and False otherwise. + **kwargs : Keyworded arguments to pass to :class:`matplotlib.offsetbox.AnchoredOffsetbox`. @@ -334,9 +340,12 @@ def __init__(self, transform, size, label, loc, size_vertical=0.5, color='white', \ fontproperties=fontprops) """ + if fill_bar is None: + fill_bar = size_vertical > 0 + self.size_bar = AuxTransformBox(transform) self.size_bar.add_artist(Rectangle((0, 0), size, size_vertical, - fill=False, facecolor=color, + fill=fill_bar, facecolor=color, edgecolor=color)) if fontproperties is None and 'prop' in kwargs: