Skip to content

Commit 56d43e6

Browse files
committed
More work on collections.
svn path=/branches/transforms/; revision=3928
1 parent 6d00dbf commit 56d43e6

File tree

10 files changed

+455
-450
lines changed

10 files changed

+455
-450
lines changed

examples/collections_demo.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
a = fig.add_subplot(2,2,1)
4646
col = collections.LineCollection([spiral], offsets=xyo,
4747
transOffset=a.transData)
48+
trans = transforms.Affine2D().scale(fig.dpi/72.0)
49+
col.set_transform(trans) # the points to pixels transform
4850
# Note: the first argument to the collection initializer
4951
# must be a list of sequences of x,y tuples; we have only
5052
# one sequence, but we still have to put it in a list.
@@ -59,9 +61,6 @@
5961

6062
# Make a transform for the line segments such that their size is
6163
# given in points:
62-
trans = transforms.scale_transform(fig.dpi/transforms.Value(72.),
63-
fig.dpi/transforms.Value(72.))
64-
col.set_transform(trans) # the points to pixels transform
6564
col.set_color(colors)
6665

6766
a.autoscale_view() # See comment above, after a.add_collection.
@@ -74,28 +73,25 @@
7473

7574
col = collections.PolyCollection([spiral], offsets=xyo,
7675
transOffset=a.transData)
77-
a.add_collection(col, autolim=True)
78-
trans = transforms.scale_transform(fig.dpi/transforms.Value(72.),
79-
fig.dpi/transforms.Value(72.))
76+
trans = transforms.Affine2D().scale(fig.dpi/72.0)
8077
col.set_transform(trans) # the points to pixels transform
78+
a.add_collection(col, autolim=True)
8179
col.set_color(colors)
8280

8381

8482
a.autoscale_view()
8583
a.set_title('PolyCollection using offsets')
8684

87-
8885
# 7-sided regular polygons
8986

9087
a = fig.add_subplot(2,2,3)
9188

9289
col = collections.RegularPolyCollection(fig.dpi, 7,
93-
sizes = N.fabs(xx)*10, offsets=xyo,
90+
sizes = N.fabs(xx) / 10.0, offsets=xyo,
9491
transOffset=a.transData)
95-
a.add_collection(col, autolim=True)
96-
trans = transforms.scale_transform(fig.dpi/transforms.Value(72.),
97-
fig.dpi/transforms.Value(72.))
92+
trans = transforms.Affine2D().scale(fig.dpi/72.0)
9893
col.set_transform(trans) # the points to pixels transform
94+
a.add_collection(col, autolim=True)
9995
col.set_color(colors)
10096
a.autoscale_view()
10197
a.set_title('RegularPolyCollection using offsets')

lib/matplotlib/axes.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def add_collection(self, collection, autolim=False):
10461046
self._set_artist_props(collection)
10471047
collection.set_clip_path(self.axesPatch)
10481048
if autolim:
1049-
self.update_datalim(collection.get_verts(self.transData))
1049+
self.update_datalim(collection.get_datalim(self.transData))
10501050
collection._remove_method = lambda h: self.collections.remove(h)
10511051

10521052
def add_line(self, line):
@@ -1105,6 +1105,9 @@ def update_datalim(self, xys):
11051105
# limits and set the bound to be the bounds of the xydata.
11061106
# Otherwise, it will compute the bounds of it's current data
11071107
# and the data in xydata
1108+
# MGDTODO: This isn't always the most efficient way to do this... in
1109+
# some cases things should use update_datalim_bounds
1110+
11081111
if not ma.isMaskedArray(xys):
11091112
xys = npy.asarray(xys)
11101113
self.update_datalim_numerix(xys[:, 0], xys[:, 1])
@@ -1119,6 +1122,10 @@ def update_datalim_numerix(self, x, y):
11191122
self.dataLim.update_from_data(x, y, self.ignore_existing_data_limits)
11201123
self.ignore_existing_data_limits = False
11211124

1125+
def update_datalim_bounds(self, bounds):
1126+
# MGDTODO: Document me
1127+
self.dataLim.bounds = Bbox.union([self.dataLim, bounds]).bounds
1128+
11221129
def _get_verts_in_data_coords(self, trans, xys):
11231130
if trans == self.transData:
11241131
return xys
@@ -4006,8 +4013,8 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40064013
shading='faceted --> edgecolors=None
40074014
edgecolors also can be any mpl color or sequence of colors.
40084015
4009-
Optional kwargs control the PatchCollection properties:
4010-
%(PatchCollection)s
4016+
Optional kwargs control the Collection properties:
4017+
%(Collection)s
40114018
"""
40124019

40134020
if not self._hold: self.cla()
@@ -4439,7 +4446,7 @@ def pcolor(self, *args, **kwargs):
44394446
44404447
* alpha=1.0 : the alpha blending value
44414448
4442-
Return value is a mcoll.PatchCollection
4449+
Return value is a mcoll.Collection
44434450
object
44444451
44454452
Grid Orientation
@@ -4627,7 +4634,7 @@ def pcolormesh(self, *args, **kwargs):
46274634
46284635
* alpha=1.0 : the alpha blending value
46294636
4630-
Return value is a collections.PatchCollection
4637+
Return value is a collections.Collection
46314638
object
46324639
46334640
See pcolor for an explantion of the grid orientation and the

lib/matplotlib/backends/backend_agg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
131131
self._renderer.draw_markers(gc, marker_path, marker_trans.frozen(), path, trans.frozen(), rgbFace)
132132

133133
def draw_path_collection(self, master_transform, clipbox, clippath, clippath_trans,
134-
paths, transforms, facecolors, edgecolors, linewidths, linestyles, antialiaseds):
134+
paths, transforms, offsets, transOffset, facecolors, edgecolors,
135+
linewidths, linestyles, antialiaseds):
135136
assert master_transform.is_affine
137+
if transOffset is not None:
138+
transOffset = transOffset.frozen()
136139
self._renderer.draw_path_collection(
137140
master_transform.frozen(), clipbox, clippath, clippath_trans,
138-
paths, transforms, facecolors, edgecolors, linewidths, linestyles, antialiaseds)
141+
paths, transforms, offsets, transOffset, facecolors, edgecolors, linewidths,
142+
linestyles, antialiaseds)
139143

140144
def draw_mathtext(self, gc, x, y, s, prop, angle):
141145
"""

0 commit comments

Comments
 (0)