From 3f2567e9149c73b9068e2601c325370a565be77f Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Mon, 3 Jul 2017 14:03:57 -0500 Subject: [PATCH 1/2] Allow users to control the fill for AnchoredSizeBar --- lib/mpl_toolkits/axes_grid1/anchored_artists.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/mpl_toolkits/axes_grid1/anchored_artists.py b/lib/mpl_toolkits/axes_grid1/anchored_artists.py index ac5eaf29039e..4005b32c821d 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=False, **kwargs): """ Draw a horizontal scale bar with a center-aligned label underneath. @@ -295,6 +295,11 @@ 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 False. + **kwargs : Keyworded arguments to pass to :class:`matplotlib.offsetbox.AnchoredOffsetbox`. @@ -336,7 +341,7 @@ def __init__(self, transform, size, label, loc, """ 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: From 48519ed2cc3c31c3caeab29fdd0d6482798efa48 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 5 Jul 2017 15:30:16 -0500 Subject: [PATCH 2/2] Implement tacaswell's suggestions --- .../whats_new/anchoredsizebar_fill_bar_argument.rst | 13 +++++++++++++ lib/mpl_toolkits/axes_grid1/anchored_artists.py | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 doc/users/whats_new/anchoredsizebar_fill_bar_argument.rst 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 4005b32c821d..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, fill_bar=False, + label_top=False, fontproperties=None, fill_bar=None, **kwargs): """ Draw a horizontal scale bar with a center-aligned label underneath. @@ -298,7 +298,8 @@ def __init__(self, transform, size, label, loc, 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 False. + Defaults to True if `size_vertical` is greater than + zero and False otherwise. **kwargs : Keyworded arguments to pass to @@ -339,6 +340,9 @@ 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=fill_bar, facecolor=color,