Skip to content

BUG/API : tweaked how AnchoredSizeBar handles font properties #2951

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 6, 2014
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
7 changes: 7 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ original location:
treated as numpy fancy indexing and only the two markers corresponding to the
given indexes will be shown.

* removed prop kwarg from `mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar`
call. It was passed through to the base-class `__init__` and is only used for
setting padding. Now `fontproperties` (which is what is really used to set
the font properties of `AnchoredSizeBar`) is passed through in place of `prop`.
If `fontpropreties` is not passed in, but `prop` is, then `prop` is used inplace
of `fontpropreties`. If both are passed in, `prop` is silently ignored.

Code removal
------------
Expand All @@ -179,6 +185,7 @@ Code removal
a long time) and was not the standard form of the Levy distribution.
``scipy.stats.levy`` should be used instead


.. _changes_in_1_3:


Expand Down
27 changes: 17 additions & 10 deletions lib/mpl_toolkits/axes_grid1/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def __init__(self, transform, width, height, angle, loc,
frameon=frameon, **kwargs)



class AnchoredSizeBar(AnchoredOffsetbox):
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2, prop=None,
pad=0.1, borderpad=0.1, sep=2,
frameon=True, size_vertical=0, color='black',
label_top=False, fontproperties=None,
**kwargs):
Expand Down Expand Up @@ -117,24 +116,32 @@ def __init__(self, transform, size, label, loc,
>>> fig.show()

Using all the optional parameters

>>> import matplotlib.font_manager as fm
>>> fontprops = fm.FontProperties(size=14, family='monospace')
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontproperties=fontprops)
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontproperties=fontprops) # noqa

"""

self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))
self.size_bar.add_artist(Rectangle((0, 0), size, size_vertical,
fill=True, facecolor=color,
edgecolor=color))

if not fontproperties:
# if fontproperties is None, but `prop` is not, assume that
# prop should be used to set the font properties. This is
# questionable behavior
if fontproperties is None and 'prop' in kwargs:
fontproperties = kwargs.pop('prop')

if fontproperties is None:
textprops = {'color': color}
else:
textprops = {'color': color, 'fontproperties': fontproperties}
textprops = {'color': color, 'fontproperties': fontproperties}

self.txt_label = TextArea(
label,
minimumdescent=False,
label,
minimumdescent=False,
textprops=textprops)

if label_top:
Expand All @@ -148,7 +155,7 @@ def __init__(self, transform, size, label, loc,

AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
child=self._box,
prop=prop,
prop=fontproperties,
frameon=frameon, **kwargs)


Expand Down