File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -519,8 +519,8 @@ def test_two_2line_texts(spacing1, spacing2):
519519 fig = plt .figure ()
520520 renderer = fig .canvas .get_renderer ()
521521
522- text1 = plt .text (0.25 , 0.5 , text_string , linespacing = spacing1 )
523- text2 = plt .text (0.25 , 0.5 , text_string , linespacing = spacing2 )
522+ text1 = fig .text (0.25 , 0.5 , text_string , linespacing = spacing1 )
523+ text2 = fig .text (0.25 , 0.5 , text_string , linespacing = spacing2 )
524524 fig .canvas .draw ()
525525
526526 box1 = text1 .get_window_extent (renderer = renderer )
@@ -534,6 +534,11 @@ def test_two_2line_texts(spacing1, spacing2):
534534 assert box1 .height != box2 .height
535535
536536
537+ def test_validate_linespacing ():
538+ with pytest .raises (TypeError ):
539+ plt .text (.25 , .5 , "foo" , linespacing = "abc" )
540+
541+
537542def test_nonfinite_pos ():
538543 fig , ax = plt .subplots ()
539544 ax .text (0 , np .nan , 'nan' )
Original file line number Diff line number Diff line change 55import functools
66import logging
77import math
8- import numbers
8+ from numbers import Real
99import weakref
1010
1111import numpy as np
@@ -181,7 +181,7 @@ def __init__(self,
181181 self ._renderer = None
182182 if linespacing is None :
183183 linespacing = 1.2 # Maybe use rcParam later.
184- self ._linespacing = linespacing
184+ self .set_linespacing ( linespacing )
185185 self .set_rotation_mode (rotation_mode )
186186 self .update (kwargs )
187187
@@ -1000,6 +1000,7 @@ def set_linespacing(self, spacing):
10001000 ----------
10011001 spacing : float (multiple of font size)
10021002 """
1003+ _api .check_isinstance (Real , spacing = spacing )
10031004 self ._linespacing = spacing
10041005 self .stale = True
10051006
@@ -1186,7 +1187,7 @@ def set_rotation(self, s):
11861187 The rotation angle in degrees in mathematically positive direction
11871188 (counterclockwise). 'horizontal' equals 0, 'vertical' equals 90.
11881189 """
1189- if isinstance (s , numbers . Real ):
1190+ if isinstance (s , Real ):
11901191 self ._rotation = float (s ) % 360
11911192 elif cbook ._str_equal (s , 'horizontal' ) or s is None :
11921193 self ._rotation = 0.
You can’t perform that action at this time.
0 commit comments