@@ -106,6 +106,7 @@ def get_rotation(rotation):
106
106
fontproperties: a matplotlib.font_manager.FontProperties instance
107
107
horizontalalignment or ha: [ 'center' | 'right' | 'left' ]
108
108
label: any string
109
+ linespacing: float
109
110
lod: [True | False]
110
111
multialignment: ['left' | 'right' | 'center' ]
111
112
name or fontname: string eg, ['Sans' | 'Courier' | 'Helvetica' ...]
@@ -144,6 +145,7 @@ def __init__(self,
144
145
multialignment = None ,
145
146
fontproperties = None , # defaults to FontProperties()
146
147
rotation = None ,
148
+ linespacing = 1.2 ,
147
149
** kwargs
148
150
):
149
151
"""
@@ -167,13 +169,14 @@ def __init__(self,
167
169
self ._fontproperties = fontproperties
168
170
self ._bbox = None
169
171
self ._renderer = None
172
+ self ._linespacing = linespacing
170
173
self .update (kwargs )
171
174
#self.set_bbox(dict(pad=0))
172
175
__init__ .__doc__ = cbook .dedent (__init__ .__doc__ ) % artist .kwdocd
173
176
174
177
def contains (self ,mouseevent ):
175
- """Test whether the mouse event occurred in the patch.
176
-
178
+ """Test whether the mouse event occurred in the patch.
179
+
177
180
Returns T/F, {}
178
181
"""
179
182
if callable (self ._contains ): return self ._contains (self ,mouseevent )
@@ -189,7 +192,7 @@ def contains(self,mouseevent):
189
192
xyverts = (l ,b ), (l , t ), (r , t ), (r , b )
190
193
x , y = mouseevent .x , mouseevent .y
191
194
inside = nxutils .pnpoly (x , y , xyverts )
192
- return inside ,{}
195
+ return inside ,{}
193
196
194
197
def _get_xy_display (self ):
195
198
'get the (possibly unit converted) transformed x,y in display coords'
@@ -227,6 +230,7 @@ def update_from(self, other):
227
230
self ._fontproperties = other ._fontproperties .copy ()
228
231
self ._rotation = other ._rotation
229
232
self ._picker = other ._picker
233
+ self ._linespacing = other ._linespacing
230
234
231
235
def _get_layout (self , renderer ):
232
236
@@ -236,7 +240,6 @@ def _get_layout(self, renderer):
236
240
key = self .get_prop_tup ()
237
241
if self .cached .has_key (key ): return self .cached [key ]
238
242
horizLayout = []
239
- pad = 2
240
243
thisx , thisy = self ._get_xy_display ()
241
244
width = 0
242
245
height = 0
@@ -248,16 +251,16 @@ def _get_layout(self, renderer):
248
251
lines = self ._text .split ('\n ' )
249
252
250
253
whs = []
254
+ # Find full vertical extent, including ascenders and descenders:
251
255
tmp , heightt = renderer .get_text_width_height (
252
- 'T ' , self ._fontproperties , ismath = False )
256
+ 'Tglp ' , self ._fontproperties , ismath = False )
253
257
254
- heightt += 3 # 3 pixel pad
255
258
for line in lines :
256
259
w ,h = renderer .get_text_width_height (
257
260
line , self ._fontproperties , ismath = self .is_math_text ())
258
261
259
262
whs .append ( (w ,h ) )
260
- offsety = heightt + pad
263
+ offsety = heightt * self . _linespacing
261
264
horizLayout .append ((line , thisx , thisy , w , h ))
262
265
thisy -= offsety # now translate down by text height, window coords
263
266
width = max (width , w )
@@ -621,6 +624,14 @@ def set_multialignment(self, align):
621
624
raise ValueError ('Horizontal alignment must be one of %s' % str (legal ))
622
625
self ._multialignment = align
623
626
627
+ def set_linespacing (self , spacing ):
628
+ """
629
+ Set the line spacing as a multiple of the font size.
630
+
631
+ ACCEPTS: float
632
+ """
633
+ self ._linespacing = spacing
634
+
624
635
def set_family (self , fontname ):
625
636
"""
626
637
Set the font family
@@ -1196,14 +1207,14 @@ def __init__(self, s, xy,
1196
1207
self .xycoords = xycoords
1197
1208
self .textcoords = textcoords
1198
1209
__init__ .__doc__ = cbook .dedent (__init__ .__doc__ )
6D40
% artist .kwdocd
1199
-
1210
+
1200
1211
def contains (self ,event ):
1201
1212
t ,tinfo = Text .contains (self ,event )
1202
1213
if self .arrow is not None :
1203
1214
a ,ainfo = self .arrow .contains (event )
1204
1215
t = t or a
1205
1216
return t ,tinfo
1206
-
1217
+
1207
1218
1208
1219
def set_clip_box (self , clipbox ):
1209
1220
"""
0 commit comments