Skip to content

Commit c312da1

Browse files
committed
Merge pull request matplotlib#3677 from jenshnielsen/fix_text
TST : Rotation angle between 0 and 360.
2 parents 78f1942 + 302bdf8 commit c312da1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/matplotlib/tests/test_text.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import six
55

66
import numpy as np
7+
from numpy.testing import assert_almost_equal
78
import matplotlib
89
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
910
import matplotlib.pyplot as plt
@@ -271,3 +272,9 @@ def test_get_rotation_raises():
271272
def test_get_rotation_none():
272273
from matplotlib import text
273274
assert text.get_rotation(None) == 0.0
275+
276+
277+
def test_get_rotation_mod360():
278+
from matplotlib import text
279+
for i, j in zip([360., 377., 720+177.2], [0., 17., 177.2]):
280+
assert_almost_equal(text.get_rotation(i), j)

lib/matplotlib/text.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def _process_text_args(override, fontdict=None, **kwargs):
4545
# Extracted from Text's method to serve as a function
4646
def get_rotation(rotation):
4747
"""
48-
Return the text angle as float.
48+
Return the text angle as float. The returned
49+
angle is between 0 and 360 deg.
4950
5051
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
5152
"""
@@ -62,7 +63,7 @@ def get_rotation(rotation):
6263
" 'vertical', numeric value or"
6364
"None".format(rotation))
6465

65-
return angle
66+
return angle % 360
6667
# these are not available for the object inspector until after the
6768
# class is build so we define an initial set here for the init
6869
# function and they will be overridden after object defn

0 commit comments

Comments
 (0)