Skip to content

Commit 98fea36

Browse files
committed
Silence UniCode error in get_rotation
Ensure that rotation is string before comparing to string and raise ValueError if rotation could not be converted to float
1 parent ad1dd48 commit 98fea36

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/matplotlib/text.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ def get_rotation(rotation):
4949
5050
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
5151
"""
52-
if rotation in ('horizontal', None):
53-
angle = 0.
54-
elif rotation == 'vertical':
55-
angle = 90.
56-
else:
52+
try:
5753
angle = float(rotation)
58-
return angle % 360
59-
54+
except (ValueError, TypeError):
55+
isString = isinstance(rotation, six.string_types)
56+
if ((isString and rotation == 'horizontal') or rotation is None):
57+
angle = 0.
58+
elif (isString and rotation == 'vertical'):
59+
angle = 90.
60+
else:
61+
raise ValueError("rotation is {0} expected either 'horizontal'"
62+
" 'vertical', numeric value or"
63+
"None".format(rotation))
6064

65+
return angle
6166
# these are not available for the object inspector until after the
6267
# class is build so we define an initial set here for the init
6368
# function and they will be overridden after object defn

0 commit comments

Comments
 (0)