Skip to content

Commit 5a9cd4e

Browse files
committed
Add widths, heights and angles setter to EllipseCollection
1 parent ff0497c commit 5a9cd4e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/matplotlib/collections.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,18 @@ def _set_transforms(self):
17951795
m[:2, 2:] = 0
17961796
self.set_transform(_affine(m))
17971797

1798+
def set_widths(self, widths):
1799+
self._widths = 0.5 * np.asarray(widths).ravel()
1800+
self.stale = True
1801+
1802+
def set_angles(self, angles):
1803+
self._angles = np.deg2rad(angles).ravel()
1804+
self.stale = True
1805+
1806+
def set_heights(self, heights):
1807+
self._heights = 0.5 * np.asarray(heights).ravel()
1808+
self.stale = True
1809+
17981810
@artist.allow_rasterization
17991811
def draw(self, renderer):
18001812
self._set_transforms()

lib/matplotlib/tests/test_collections.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,37 @@ def test_EllipseCollection():
408408
ax.autoscale_view()
409409

410410

411+
def test_EllipseCollection_setter():
412+
# Test widths, heights and angle setter
413+
rng = np.random.default_rng(0)
414+
415+
widths = (2, )
416+
heights = (3, )
417+
angles = (45, )
418+
offsets = rng.random((10, 2)) * 10
419+
420+
fig, ax = plt.subplots()
421+
422+
ec = mcollections.EllipseCollection(
423+
widths=widths,
424+
heights=heights,
425+
angles=angles,
426+
offsets=offsets,
427+
units='x',
428+
offset_transform=ax.transData,
429+
)
430+
431+
ax.add_collection(ec)
432+
ax.set_xlim(-2, 12)
433+
ax.set_ylim(-2, 12)
434+
435+
new_widths = rng.random((10, 2)) * 2
436+
new_heights = rng.random((10, 2)) * 3
437+
new_angles = rng.random((10, 2)) * 180
438+
439+
ec.set(widths=new_widths, heights=new_heights, angles=new_angles)
440+
441+
411442
@image_comparison(['polycollection_close.png'], remove_text=True, style='mpl20')
412443
def test_polycollection_close():
413444
from mpl_toolkits.mplot3d import Axes3D # type: ignore

0 commit comments

Comments
 (0)