Skip to content

Commit

Permalink
Merge pull request #3677 from jenshnielsen/fix_text
Browse files Browse the repository at this point in the history
TST : Rotation angle between 0 and 360.
  • Loading branch information
tacaswell committed Oct 19, 2014
2 parents 78f1942 + 302bdf8 commit c312da1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_text.py
Expand Up @@ -4,6 +4,7 @@
import six

import numpy as np
from numpy.testing import assert_almost_equal
import matplotlib
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -271,3 +272,9 @@ def test_get_rotation_raises():
def test_get_rotation_none():
from matplotlib import text
assert text.get_rotation(None) == 0.0


def test_get_rotation_mod360():
from matplotlib import text
for i, j in zip([360., 377., 720+177.2], [0., 17., 177.2]):
assert_almost_equal(text.get_rotation(i), j)
5 changes: 3 additions & 2 deletions lib/matplotlib/text.py
Expand Up @@ -45,7 +45,8 @@ def _process_text_args(override, fontdict=None, **kwargs):
# Extracted from Text's method to serve as a function
def get_rotation(rotation):
"""
Return the text angle as float.
Return the text angle as float. The returned
angle is between 0 and 360 deg.
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
"""
Expand All @@ -62,7 +63,7 @@ def get_rotation(rotation):
" 'vertical', numeric value or"
"None".format(rotation))

return angle
return angle % 360
# these are not available for the object inspector until after the
# class is build so we define an initial set here for the init
# function and they will be overridden after object defn
Expand Down

0 comments on commit c312da1

Please sign in to comment.