Skip to content

Commit 638adf4

Browse files
committed
Merge pull request #3574 from mdboom/regular-polygon-rotation
BUG : `rotation` parameter had no effect on `RegularPolyCollection`
2 parents 9dbf4eb + 19476de commit 638adf4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/matplotlib/collections.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,15 @@ def get_numsides(self):
927927
def get_rotation(self):
928928
return self._rotation
929929

930+
@allow_rasterization
931+
def draw(self, renderer):
932+
self.set_sizes(self._sizes, self.figure.dpi)
933+
self._transforms = [
934+
transforms.Affine2D(x).rotate(-self._rotation).get_matrix()
935+
for x in self._transforms
936+
]
937+
Collection.draw(self, renderer)
938+
930939

931940
class StarPolygonCollection(RegularPolyCollection):
932941
"""
78.8 KB
Loading

lib/matplotlib/tests/test_collections.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ def test_polycollection_close():
513513
ax.set_ylim3d(0, 4)
514514

515515

516+
@image_comparison(baseline_images=['regularpolycollection_rotate'],
517+
extensions=['png'], remove_text=True)
518+
def test_regularpolycollection_rotate():
519+
xx, yy = np.mgrid[:10, :10]
520+
xy_points = np.transpose([xx.flatten(), yy.flatten()])
521+
rotations = np.linspace(0, 2*np.pi, len(xy_points))
522+
523+
fig, ax = plt.subplots()
524+
for xy, alpha in zip(xy_points, rotations):
525+
col = mcollections.RegularPolyCollection(
526+
4, sizes=(100,), rotation=alpha,
527+
offsets=xy, transOffset=ax.transData)
528+
ax.add_collection(col, autolim=True)
529+
ax.autoscale_view()
530+
531+
516532
if __name__ == '__main__':
517533
import nose
518534
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)