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

Skip to content

Commit d7d06ad

Browse files
committed
Modified EllipseCollection for closer compatibility with Ellipse patch.
svn path=/trunk/matplotlib/; revision=8111
1 parent b61448c commit d7d06ad

3 files changed

Lines changed: 57 additions & 40 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-02-06 Added 'xy' scaling option to EllipseCollection. - EF
2+
13
2010-02-03 Made plot_directive use a custom PlotWarning category, so that
24
warnings can be turned into fatal errors easily if desired. - FP
35

doc/api/api_changes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ list may help describe what changes may be necessary in your code.
1010
Changes beyond 0.99.x
1111
=====================
1212

13+
* The :class:'~matplotlib.collections.EllipseCollection' has been
14+
changed in two ways:
15+
16+
+ There is a new *units* option, 'xy', that scales the ellipse with
17+
the data units. This matches the :class:'~matplotlib.patches.Ellipse`
18+
scaling.
19+
20+
+ The *height* and *width* kwargs have been changed to specify
21+
the height and width, again for consistency with
22+
:class:'~matplotlib.patches.Ellipse`, and to better match
23+
their names; previously they specified the half-height and
24+
half-width.
25+
1326
* There is a new rc parameter ``axes.color_cycle``, and the color
1427
cycle is now independent of the rc parameter ``lines.color``.
1528
:func:`matplotlib.Axes.set_default_color_cycle` is deprecated.

lib/matplotlib/collections.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -918,77 +918,79 @@ class EllipseCollection(Collection):
918918
def __init__(self, widths, heights, angles, units='points', **kwargs):
919919
"""
920920
*widths*: sequence
921-
half-lengths of first axes (e.g., semi-major axis lengths)
921+
lengths of first axes (e.g., major axis lengths)
922922
923923
*heights*: sequence
924-
half-lengths of second axes
924+
lengths of second axes
925925
926926
*angles*: sequence
927927
angles of first axes, degrees CCW from the X-axis
928928
929-
*units*: ['points' | 'inches' | 'dots' | 'width' | 'height' | 'x' | 'y']
929+
*units*: ['points' | 'inches' | 'dots' | 'width' | 'height'
930+
| 'x' | 'y' | 'xy']
930931
units in which majors and minors are given; 'width' and 'height'
931932
refer to the dimensions of the axes, while 'x' and 'y'
932-
refer to the *offsets* data units.
933+
refer to the *offsets* data units. 'xy' differs from all
934+
others in that the angle as plotted varies with the
935+
aspect ratio, and equals the specified angle only when
936+
the aspect ratio is unity. Hence it behaves the same
937+
as the :class:`~matplotlib.patches.Ellipse` with
938+
axes.transData as its transform.
933939
934940
Additional kwargs inherited from the base :class:`Collection`:
935941
936942
%(Collection)s
937943
"""
938944
Collection.__init__(self,**kwargs)
939-
self._widths = np.asarray(widths).ravel()
940-
self._heights = np.asarray(heights).ravel()
945+
self._widths = 0.5 * np.asarray(widths).ravel()
946+
self._heights = 0.5 * np.asarray(heights).ravel()
941947
self._angles = np.asarray(angles).ravel() *(np.pi/180.0)
942948
self._units = units
943949
self.set_transform(transforms.IdentityTransform())
944950
self._transforms = []
945951
self._paths = [mpath.Path.unit_circle()]
946-
self._initialized = False
947952

948-
949-
def _init(self):
950-
def on_dpi_change(fig):
951-
self._transforms = []
952-
self.figure.callbacks.connect('dpi_changed', on_dpi_change)
953-
self._initialized = True
954-
955-
def set_transforms(self):
956-
if not self._initialized:
957-
self._init()
953+
def _set_transforms(self):
954+
"""
955+
Calculate transforms immediately before drawing.
956+
"""
958957
self._transforms = []
959958
ax = self.axes
960959
fig = self.figure
961-
if self._units in ('x', 'y'):
962-
if self._units == 'x':
963-
dx0 = ax.viewLim.width
964-
dx1 = ax.bbox.width
965-
else:
966-
dx0 = ax.viewLim.height
967-
dx1 = ax.bbox.height
968-
sc = dx1/dx0
960+
961+
if self._units == 'xy':
962+
sc = 1
963+
elif self._units == 'x':
964+
sc = ax.bbox.width / ax.viewLim.width
965+
elif self._units == 'y':
966+
sc = ax.bbox.height / ax.viewLim.height
967+
elif self._units == 'inches':
968+
sc = fig.dpi
969+
elif self._units == 'points':
970+
sc = fig.dpi / 72.0
971+
elif self._units == 'width':
972+
sc = ax.bbox.width
973+
elif self._units == 'height':
974+
sc = ax.bbox.height
975+
elif self._units == 'dots':
976+
sc = 1.0
969977
else:
970-
if self._units == 'inches':
971-
sc = fig.dpi
972-
elif self._units == 'points':
973-
sc = fig.dpi / 72.0
974-
elif self._units == 'width':
975-
sc = ax.bbox.width
976-
elif self._units == 'height':
977-
sc = ax.bbox.height
978-
elif self._units == 'dots':
979-
sc = 1.0
980-
else:
981-
raise ValueError('unrecognized units: %s' % self._units)
978+
raise ValueError('unrecognized units: %s' % self._units)
982979

983980
_affine = transforms.Affine2D
984981
for x, y, a in zip(self._widths, self._heights, self._angles):
985982
trans = _affine().scale(x * sc, y * sc).rotate(a)
986983
self._transforms.append(trans)
987984

985+
if self._units == 'xy':
986+
m = ax.transData.get_affine().get_matrix().copy()
987+
m[:2, 2:] = 0
988+
self.set_transform(_affine(m))
989+
990+
988991
def draw(self, renderer):
989-
if True: ###not self._transforms:
990-
self.set_transforms()
991-
return Collection.draw(self, renderer)
992+
self._set_transforms()
993+
Collection.draw(self, renderer)
992994

993995
class PatchCollection(Collection):
994996
"""

0 commit comments

Comments
 (0)