Skip to content

Commit e0be268

Browse files
committed
Merge pull request #2951 from tacaswell/anchoredsizebox_text
BUG/API : tweaked how AnchoredSizeBar handles font properties
2 parents abfcde6 + 40c4fe7 commit e0be268

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

doc/api/api_changes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ original location:
177177
treated as numpy fancy indexing and only the two markers corresponding to the
178178
given indexes will be shown.
179179

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

181187
Code removal
182188
------------
@@ -185,6 +191,7 @@ Code removal
185191
a long time) and was not the standard form of the Levy distribution.
186192
``scipy.stats.levy`` should be used instead
187193

194+
188195
.. _changes_in_1_3:
189196

190197

lib/mpl_toolkits/axes_grid1/anchored_artists.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ def __init__(self, transform, width, height, angle, loc,
6666
frameon=frameon, **kwargs)
6767

6868

69-
7069
class AnchoredSizeBar(AnchoredOffsetbox):
7170
def __init__(self, transform, size, label, loc,
72-
pad=0.1, borderpad=0.1, sep=2, prop=None,
71+
pad=0.1, borderpad=0.1, sep=2,
7372
frameon=True, size_vertical=0, color='black',
7473
label_top=False, fontproperties=None,
7574
**kwargs):
@@ -117,24 +116,32 @@ def __init__(self, transform, size, label, loc,
117116
>>> fig.show()
118117
119118
Using all the optional parameters
120-
119+
121120
>>> import matplotlib.font_manager as fm
122121
>>> fontprops = fm.FontProperties(size=14, family='monospace')
123-
>>> 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)
122+
>>> 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
124123
125124
"""
126125

127126
self.size_bar = AuxTransformBox(transform)
128-
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))
127+
self.size_bar.add_artist(Rectangle((0, 0), size, size_vertical,
128+
fill=True, facecolor=color,
129+
edgecolor=color))
129130

130-
if not fontproperties:
131+
# if fontproperties is None, but `prop` is not, assume that
132+
# prop should be used to set the font properties. This is
133+
# questionable behavior
134+
if fontproperties is None and 'prop' in kwargs:
135+
fontproperties = kwargs.pop('prop')
136+
137+
if fontproperties is None:
131138
textprops = {'color': color}
132139
else:
133-
textprops = {'color': color, 'fontproperties': fontproperties}
140+
textprops = {'color': color, 'fontproperties': fontproperties}
134141

135142
self.txt_label = TextArea(
136-
label,
137-
minimumdescent=False,
143+
label,
144+
minimumdescent=False,
138145
textprops=textprops)
139146

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

149156
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
150157
child=self._box,
151-
prop=prop,
158+
prop=fontproperties,
152159
frameon=frameon, **kwargs)
153160

154161

0 commit comments

Comments
 (0)