File tree 2 files changed +11
-5
lines changed 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):
519
519
fig = plt .figure ()
520
520
renderer = fig .canvas .get_renderer ()
521
521
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 )
524
524
fig .canvas .draw ()
525
525
526
526
box1 = text1 .get_window_extent (renderer = renderer )
@@ -534,6 +534,11 @@ def test_two_2line_texts(spacing1, spacing2):
534
534
assert box1 .height != box2 .height
535
535
536
536
537
+ def test_validate_linespacing ():
538
+ with pytest .raises (TypeError ):
539
+ plt .text (.25 , .5 , "foo" , linespacing = "abc" )
540
+
541
+
537
542
def test_nonfinite_pos ():
538
543
fig , ax = plt .subplots ()
539
544
ax .text (0 , np .nan , 'nan' )
Original file line number Diff line number Diff line change 5
5
import functools
6
6
import logging
7
7
import math
8
- import numbers
8
+ from numbers import Real
9
9
import weakref
10
10
11
11
import numpy as np
@@ -181,7 +181,7 @@ def __init__(self,
181
181
self ._renderer = None
182
182
if linespacing is None :
183
183
linespacing = 1.2 # Maybe use rcParam later.
184
- self ._linespacing = linespacing
184
+ self .set_linespacing ( linespacing )
185
185
self .set_rotation_mode (rotation_mode )
186
186
self .update (kwargs )
187
187
@@ -1000,6 +1000,7 @@ def set_linespacing(self, spacing):
1000
1000
----------
1001
1001
spacing : float (multiple of font size)
1002
1002
"""
1003
+ _api .check_isinstance (Real , spacing = spacing )
1003
1004
self ._linespacing = spacing
1004
1005
self .stale = True
1005
1006
@@ -1186,7 +1187,7 @@ def set_rotation(self, s):
1186
1187
The rotation angle in degrees in mathematically positive direction
1187
1188
(counterclockwise). 'horizontal' equals 0, 'vertical' equals 90.
1188
1189
"""
1189
- if isinstance (s , numbers . Real ):
1190
+ if isinstance (s , Real ):
1190
1191
self ._rotation = float (s ) % 360
1191
1192
elif cbook ._str_equal (s , 'horizontal' ) or s is None :
1192
1193
self ._rotation = 0.
You can’t perform that action at this time.
0 commit comments