Skip to content

Commit

Permalink
Merge pull request #2951 from tacaswell/anchoredsizebox_text
Browse files Browse the repository at this point in the history
BUG/API : tweaked how AnchoredSizeBar handles font properties
  • Loading branch information
WeatherGod committed Jul 6, 2014
2 parents abfcde6 + 40c4fe7 commit e0be268
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions doc/api/api_changes.rst
Expand Up @@ -177,6 +177,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 @@ -185,6 +191,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
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

0 comments on commit e0be268

Please sign in to comment.