@@ -241,7 +241,7 @@ def _reset_visual_defaults(
241241 self ._bbox_patch = None # a FancyBboxPatch instance
242242 self ._renderer = None
243243 if linespacing is None :
244- linespacing = 1.2 # Maybe use rcParam later.
244+ linespacing = 'normal' # Maybe use rcParam later.
245245 self .set_linespacing (linespacing )
246246 self .set_rotation_mode (rotation_mode )
247247 self .set_antialiased (mpl ._val_or_rc (antialiased , 'text.antialiased' ))
@@ -439,7 +439,8 @@ def _get_layout(self, renderer):
439439 ismath = "TeX" if self .get_usetex () else False ,
440440 dpi = self .get_figure (root = True ).dpi )
441441 lp_a = lp_h - lp_d
442- min_dy = lp_a * self ._linespacing
442+ linespacing = 1.2 if self ._linespacing == 'normal' else self ._linespacing
443+ min_dy = lp_a * linespacing
443444
444445 for i , line in enumerate (lines ):
445446 clean_line , ismath = self ._preprocess_math (line )
@@ -462,7 +463,7 @@ def _get_layout(self, renderer):
462463 if i == 0 : # position at baseline
463464 thisy = - a
464465 else : # put baseline a good distance from bottom of previous line
465- thisy -= max (min_dy , a * self . _linespacing )
466+ thisy -= max (min_dy , a * linespacing )
466467
467468 wads .append ((w , a , d ))
468469 xs .append (thisx ) # == 0.
@@ -1122,18 +1123,26 @@ def set_multialignment(self, align):
11221123
11231124 def set_linespacing (self , spacing ):
11241125 """
1125- Set the line spacing as a multiple of the font size.
1126-
1127- The default line spacing is 1.2.
1126+ Set the line spacing.
11281127
11291128 Parameters
11301129 ----------
1131- spacing : float (multiple of font size)
1130+ spacing : 'normal' or float, default: 'normal'
1131+ If 'normal', then the line spacing is automatically determined by font
1132+ metrics for each line individually.
1133+
1134+ If a float, then line spacing will be fixed to this multiple of the font
1135+ size for every line.
11321136 """
1133- _api .check_isinstance (Real , spacing = spacing )
1137+ if not cbook ._str_equal (spacing , 'normal' ):
1138+ _api .check_isinstance (Real , spacing = spacing )
11341139 self ._linespacing = spacing
11351140 self .stale = True
11361141
1142+ def get_linespacing (self ):
1143+ """Get the line spacing."""
1144+ return self ._linespacing
1145+
11371146 def set_fontfamily (self , fontname ):
11381147 """
11391148 Set the font family. Can be either a single string, or a list of
0 commit comments