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

Skip to content

Commit 140aedf

Browse files
committed
BUG: EllipseCollection: fix transform error
The bug was introduced in commit b8726d0, and affected both the orientation and the shape of the ellipses.
1 parent 8ada91f commit 140aedf

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/matplotlib/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,8 @@ def _set_transforms(self):
14381438
self._transforms = np.zeros((len(self._widths), 3, 3))
14391439
widths = self._widths * sc
14401440
heights = self._heights * sc
1441-
sin_angle = np.cos(np.deg2rad(self._angles))
1442-
cos_angle = np.cos(np.deg2rad(self._angles))
1441+
sin_angle = np.sin(self._angles)
1442+
cos_angle = np.cos(self._angles)
14431443
self._transforms[:, 0, 0] = widths * cos_angle
14441444
self._transforms[:, 0, 1] = heights * -sin_angle
14451445
self._transforms[:, 1, 0] = widths * sin_angle

lib/matplotlib/tests/test_collections.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,31 @@ def test_barb_limits():
450450
assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6),
451451
decimal=1)
452452

453+
454+
@image_comparison(baseline_images=['EllipseCollection_test_image'],
455+
extensions=['png'],
456+
remove_text=True)
457+
def test_EllipseCollection():
458+
# Test basic functionality
459+
fig, ax = plt.subplots()
460+
x = np.arange(4)
461+
y = np.arange(3)
462+
X, Y = np.meshgrid(x, y)
463+
XY = np.vstack((X.ravel(), Y.ravel())).T
464+
465+
ww = X/float(x[-1])
466+
hh = Y/float(y[-1])
467+
aa = np.ones_like(ww) * 20 # first axis is 20 degrees CCW from x axis
468+
469+
ec = mcollections.EllipseCollection(ww, hh, aa,
470+
units='x',
471+
offsets=XY,
472+
transOffset=ax.transData,
473+
facecolors='none')
474+
ax.add_collection(ec)
475+
ax.autoscale_view()
476+
477+
453478
if __name__ == '__main__':
454479
import nose
455480
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)