@@ -1720,8 +1720,11 @@ def __init__(self, sizes, **kwargs):
1720
1720
self ._paths = [mpath .Path .unit_circle ()]
1721
1721
1722
1722
1723
- class EllipseCollection (Collection ):
1724
- """A collection of ellipses, drawn using splines."""
1723
+ class _CollectionWithWidthHeightAngle (Collection ):
1724
+ """
1725
+ Base class for collections that have an array of widths, heights and angles
1726
+ """
1727
+ _factor = 1
1725
1728
1726
1729
def __init__ (self , widths , heights , angles , * , units = 'points' , ** kwargs ):
1727
1730
"""
@@ -1751,7 +1754,7 @@ def __init__(self, widths, heights, angles, *, units='points', **kwargs):
1751
1754
self ._units = units
1752
1755
self .set_transform (transforms .IdentityTransform ())
1753
1756
self ._transforms = np .empty ((0 , 3 , 3 ))
1754
- self ._paths = [mpath . Path . unit_circle ()]
1757
+ self ._paths = [self . _path_generator ()]
1755
1758
1756
1759
def _set_transforms (self ):
1757
1760
"""Calculate transforms immediately before drawing."""
@@ -1797,12 +1800,12 @@ def _set_transforms(self):
1797
1800
1798
1801
def set_widths (self , widths ):
1799
1802
"""Set the lengths of the first axes (e.g., major axis)."""
1800
- self ._widths = 0.5 * np .asarray (widths ).ravel ()
1803
+ self ._widths = self . _factor * np .asarray (widths ).ravel ()
1801
1804
self .stale = True
1802
1805
1803
1806
def set_heights (self , heights ):
1804
1807
"""Set the lengths of second axes (e.g., minor axes)."""
1805
- self ._heights = 0.5 * np .asarray (heights ).ravel ()
1808
+ self ._heights = self . _factor * np .asarray (heights ).ravel ()
1806
1809
self .stale = True
1807
1810
1808
1811
def set_angles (self , angles ):
@@ -1812,11 +1815,11 @@ def set_angles(self, angles):
1812
1815
1813
1816
def get_widths (self ):
1814
1817
"""Get the lengths of the first axes (e.g., major axis)."""
1815
- return self ._widths * 2
1818
+ return self ._widths / self . _factor
1816
1819
1817
1820
def get_heights (self ):
1818
1821
"""Set the lengths of second axes (e.g., minor axes)."""
1819
- return self ._heights * 2
1822
+ return self ._heights / self . _factor
1820
1823
1821
1824
def get_angles (self ):
1822
1825
"""Get the angles of the first axes, degrees CCW from the x-axis."""
@@ -1828,6 +1831,60 @@ def draw(self, renderer):
1828
1831
super ().draw (renderer )
1829
1832
1830
1833
1834
+ class EllipseCollection (_CollectionWithWidthHeightAngle ):
1835
+ """
1836
+ A collection of ellipses, drawn using splines.
1837
+
1838
+ Parameters
1839
+ ----------
1840
+ widths : array-like
1841
+ The lengths of the first axes (e.g., major axis lengths).
1842
+ heights : array-like
1843
+ The lengths of second axes.
1844
+ angles : array-like
1845
+ The angles of the first axes, degrees CCW from the x-axis.
1846
+ units : {'points', 'inches', 'dots', 'width', 'height', 'x', 'y', 'xy'}
1847
+ The units in which majors and minors are given; 'width' and
1848
+ 'height' refer to the dimensions of the axes, while 'x' and 'y'
1849
+ refer to the *offsets* data units. 'xy' differs from all others in
1850
+ that the angle as plotted varies with the aspect ratio, and equals
1851
+ the specified angle only when the aspect ratio is unity. Hence
1852
+ it behaves the same as the `~.patches.Ellipse` with
1853
+ ``axes.transData`` as its transform.
1854
+ **kwargs
1855
+ Forwarded to `Collection`.
1856
+ """
1857
+ _path_generator = mpath .Path .unit_circle
1858
+ _factor = 0.5
1859
+
1860
+
1861
+ class RectangleCollection (_CollectionWithWidthHeightAngle ):
1862
+ """
1863
+ A collection of rectangles, drawn using splines.
1864
+
1865
+ Parameters
1866
+ ----------
1867
+ widths : array-like
1868
+ The lengths of the first axes (e.g., major axis lengths).
1869
+ heights : array-like
1870
+ The lengths of second axes.
1871
+ angles : array-like
1872
+ The angles of the first axes, degrees CCW from the x-axis.
1873
+ units : {'points', 'inches', 'dots', 'width', 'height', 'x', 'y', 'xy'}
1874
+ The units in which majors and minors are given; 'width' and
1875
+ 'height' refer to the dimensions of the axes, while 'x' and 'y'
1876
+ refer to the *offsets* data units. 'xy' differs from all others in
1877
+ that the angle as plotted varies with the aspect ratio, and equals
1878
+ the specified angle only when the aspect ratio is unity. Hence
1879
+ it behaves the same as the `~.patches.Ellipse` with
1880
+ ``axes.transData`` as its transform.
1881
+ **kwargs
1882
+ Forwarded to `Collection`.
1883
+
1884
+ """
1885
+ _path_generator = mpath .Path .unit_rectangle
1886
+
1887
+
1831
1888
class PatchCollection (Collection ):
1832
1889
"""
1833
1890
A generic collection of patches.
0 commit comments