Skip to content

Commit 57ea00c

Browse files
committed
BUG/API : tweaked how AnchoredSizeBar handles font properties
- removed the explicit `prop` from `mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar` - pass `fontproperties` through to the base class in place of `prop` - if `prop` is not None and `fontproperties` is None, then use `prop` in place of `fontproperties`.
1 parent 6bbfae6 commit 57ea00c

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

doc/api/api_changes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ original location:
171171
treated as numpy fancy indexing and only the two markers corresponding to the
172172
given indexes will be shown.
173173

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

175181
Code removal
176182
------------
@@ -179,6 +185,8 @@ Code removal
179185
a long time) and was not the standard form of the Levy distribution.
180186
``scipy.stats.levy`` should be used instead
181187

188+
189+
>>>>>>> BUG/API : tweaked how AnchoredSizeBar handles font properties
182190
.. _changes_in_1_3:
183191

184192

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)