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

Skip to content

Allow users to control the fill for AnchoredSizeBar #8835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/users/whats_new/anchoredsizebar_fill_bar_argument.rst
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 11 additions & 2 deletions lib/mpl_toolkits/axes_grid1/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand Down