@@ -106,6 +106,7 @@ def get_rotation(rotation):
106106 fontproperties: a matplotlib.font_manager.FontProperties instance
107107 horizontalalignment or ha: [ 'center' | 'right' | 'left' ]
108108 label: any string
109+ linespacing: float
109110 lod: [True | False]
110111 multialignment: ['left' | 'right' | 'center' ]
111112 name or fontname: string eg, ['Sans' | 'Courier' | 'Helvetica' ...]
@@ -144,6 +145,7 @@ def __init__(self,
144145 multialignment = None ,
145146 fontproperties = None , # defaults to FontProperties()
146147 rotation = None ,
148+ linespacing = 1.2 ,
147149 ** kwargs
148150 ):
149151 """
@@ -167,13 +169,14 @@ def __init__(self,
167169 self ._fontproperties = fontproperties
168170 self ._bbox = None
169171 self ._renderer = None
172+ self ._linespacing = linespacing
170173 self .update (kwargs )
171174 #self.set_bbox(dict(pad=0))
172175 __init__ .__doc__ = cbook .dedent (__init__ .__doc__ ) % artist .kwdocd
173176
174177 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+
177180 Returns T/F, {}
178181 """
179182 if callable (self ._contains ): return self ._contains (self ,mouseevent )
@@ -189,7 +192,7 @@ def contains(self,mouseevent):
189192 xyverts = (l ,b ), (l , t ), (r , t ), (r , b )
190193 x , y = mouseevent .x , mouseevent .y
191194 inside = nxutils .pnpoly (x , y , xyverts )
192- return inside ,{}
195+ return inside ,{}
193196
194197 def _get_xy_display (self ):
195198 'get the (possibly unit converted) transformed x,y in display coords'
@@ -227,6 +230,7 @@ def update_from(self, other):
227230 self ._fontproperties = other ._fontproperties .copy ()
228231 self ._rotation = other ._rotation
229232 self ._picker = other ._picker
233+ self ._linespacing = other ._linespacing
230234
231235 def _get_layout (self , renderer ):
232236
@@ -236,7 +240,6 @@ def _get_layout(self, renderer):
236240 key = self .get_prop_tup ()
237241 if self .cached .has_key (key ): return self .cached [key ]
238242 horizLayout = []
239- pad = 2
240243 thisx , thisy = self ._get_xy_display ()
241244 width = 0
242245 height = 0
@@ -248,16 +251,16 @@ def _get_layout(self, renderer):
248251 lines = self ._text .split ('\n ' )
249252
250253 whs = []
254+ # Find full vertical extent, including ascenders and descenders:
251255 tmp , heightt = renderer .get_text_width_height (
252- 'T ' , self ._fontproperties , ismath = False )
256+ 'Tglp ' , self ._fontproperties , ismath = False )
253257
254- heightt += 3 # 3 pixel pad
255258 for line in lines :
256259 w ,h = renderer .get_text_width_height (
257260 line , self ._fontproperties , ismath = self .is_math_text ())
258261
259262 whs .append ( (w ,h ) )
260- offsety = heightt + pad
263+ offsety = heightt * self . _linespacing
261264 horizLayout .append ((line , thisx , thisy , w , h ))
262265 thisy -= offsety # now translate down by text height, window coords
263266 width = max (width , w )
@@ -621,6 +624,14 @@ def set_multialignment(self, align):
621624 raise ValueError ('Horizontal alignment must be one of %s' % str (legal ))
622625 self ._multialignment = align
623626
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+
624635 def set_family (self , fontname ):
625636 """
626637 Set the font family
@@ -1196,14 +1207,14 @@ def __init__(self, s, xy,
11961207 self .xycoords = xycoords
11971208 self .textcoords = textcoords
11981209 __init__ .__doc__ = cbook .dedent (__init__ .__doc__ ) % artist .kwdocd
1199-
1210+
12001211 def contains (self ,event ):
12011212 t ,tinfo = Text .contains (self ,event )
12021213 if self .arrow is not None :
12031214 a ,ainfo = self .arrow .contains (event )
12041215 t = t or a
12051216 return t ,tinfo
1206-
1217+
12071218
12081219 def set_clip_box (self , clipbox ):
12091220 """
0 commit comments