Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation angle between 0 and 360. #3677

Merged
merged 1 commit into from Oct 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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