Skip to content

Commit bdde2e9

Browse files
committed
Add getters to EllipseColletion
1 parent ed91d6e commit bdde2e9

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/matplotlib/collections.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1805,20 +1805,32 @@ def _set_angles(self, angles):
18051805
self._angles = np.deg2rad(angles).ravel()
18061806

18071807
def set_widths(self, widths):
1808-
"""Set the lengths of the first axes (e.g., major axis lengths)."""
1808+
"""Set the lengths of the first axes (e.g., major axis)."""
18091809
self._set_widths(widths)
18101810
self.stale = True
18111811

18121812
def set_heights(self, heights):
1813-
"""Set the lengths of second axes.."""
1813+
"""Set the lengths of second axes (e.g., minor axes)."""
18141814
self._set_heights(heights)
18151815
self.stale = True
18161816

1817+
def get_widths(self):
1818+
"""Get the lengths of the first axes (e.g., major axis)."""
1819+
return self._widths * 2
1820+
1821+
def get_heights(self):
1822+
"""Set the lengths of second axes (e.g., minor axes)."""
1823+
return self._heights * 2
1824+
18171825
def set_angles(self, angles):
18181826
"""Set the angles of the first axes, degrees CCW from the x-axis."""
18191827
self._set_angles(angles)
18201828
self.stale = True
18211829

1830+
def get_angles(self):
1831+
"""Get the angles of the first axes, degrees CCW from the x-axis."""
1832+
return np.rad2deg(self._angles)
1833+
18221834
@artist.allow_rasterization
18231835
def draw(self, renderer):
18241836
self._set_transforms()

lib/matplotlib/collections.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ class EllipseCollection(Collection):
181181
**kwargs
182182
) -> None: ...
183183
def set_widths(self, widths: ArrayLike) -> None: ...
184+
def get_widths(self) -> ArrayLike: ...
184185
def set_heights(self, heights: ArrayLike) -> None: ...
186+
def get_heights(self) -> ArrayLike: ...
185187
def set_angles(self, angles: ArrayLike) -> None: ...
188+
def get_angles(self) -> ArrayLike: ...
186189

187190
class PatchCollection(Collection):
188191
def __init__(

lib/matplotlib/tests/test_collections.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def test_EllipseCollection():
408408
ax.autoscale_view()
409409

410410

411-
def test_EllipseCollection_setter():
411+
def test_EllipseCollection_setter_getter():
412412
# Test widths, heights and angle setter
413413
rng = np.random.default_rng(0)
414414

@@ -432,6 +432,10 @@ def test_EllipseCollection_setter():
432432
assert_array_almost_equal(ec._heights, np.array(heights).ravel() * 0.5)
433433
assert_array_almost_equal(ec._angles, np.deg2rad(angles).ravel())
434434

435+
assert_array_almost_equal(ec.get_widths(), widths)
436+
assert_array_almost_equal(ec.get_heights(), heights)
437+
assert_array_almost_equal(ec.get_angles(), angles)
438+
435439
ax.add_collection(ec)
436440
ax.set_xlim(-2, 12)
437441
ax.set_ylim(-2, 12)
@@ -442,9 +446,9 @@ def test_EllipseCollection_setter():
442446

443447
ec.set(widths=new_widths, heights=new_heights, angles=new_angles)
444448

445-
assert_array_almost_equal(ec._widths, np.array(new_widths).ravel() * 0.5)
446-
assert_array_almost_equal(ec._heights, np.array(new_heights).ravel() * 0.5)
447-
assert_array_almost_equal(ec._angles, np.deg2rad(new_angles).ravel())
449+
assert_array_almost_equal(ec.get_widths(), new_widths.ravel())
450+
assert_array_almost_equal(ec.get_heights(), new_heights.ravel())
451+
assert_array_almost_equal(ec.get_angles(), new_angles.ravel())
448452

449453

450454
@image_comparison(['polycollection_close.png'], remove_text=True, style='mpl20')

0 commit comments

Comments
 (0)