Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Raise missing ValueError in transform_angles #4458

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from nose.tools import assert_equal, assert_raises
import numpy.testing as np_test
from numpy.testing import assert_almost_equal, assert_array_equal
from numpy.testing import assert_array_almost_equal
from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox
from matplotlib.path import Path
from matplotlib.scale import LogScale
Expand Down Expand Up @@ -535,6 +536,22 @@ def test_nan_overlap():
assert not a.overlaps(b)


def test_transform_angles():
t = mtrans.Affine2D() # Identity transform
angles = np.array([20, 45, 60])
points = np.array([[0, 0], [1, 1], [2, 2]])

# Identity transform does not change angles
new_angles = t.transform_angles(angles, points)
assert_array_almost_equal(angles, new_angles)

# points missing a 2nd dimension
assert_raises(ValueError, t.transform_angles, angles, points[0:2, 0:1])

# Number of angles != Number of points
assert_raises(ValueError, t.transform_angles, angles, points[0:2, :])


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
3 changes: 2 additions & 1 deletion lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,9 +1468,10 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
if pts.shape[1] != 2:
raise ValueError("'pts' must be array with 2 columns for x,y")

if angles.ndim!=1 or angles.shape[0] != pts.shape[0]:
if angles.ndim != 1 or angles.shape[0] != pts.shape[0]:
msg = "'angles' must be a column vector and have same number of"
msg += " rows as 'pts'"
raise ValueError(msg)

# Convert to radians if desired
if not radians:
Expand Down