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

Skip to content

Commit 9a72ae4

Browse files
committed
Fix dpi-changing-related bugs in Axes.scatter()
svn path=/trunk/matplotlib/; revision=5403
1 parent d262778 commit 9a72ae4

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-06-05 Fix some dpi-changing-related problems with PolyCollection,
2+
as called by Axes.scatter() - MGD
3+
14
2008-06-05 Fix image drawing so there is no extra space to the right
25
or bottom - MGD
36

examples/api/collections_demo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
spiral = zip(xx,yy)
3434

3535
# Make some offsets
36-
xo = N.random.randn(npts)
37-
yo = N.random.randn(npts)
36+
rs = N.random.RandomState([12345678])
37+
xo = rs.randn(npts)
38+
yo = rs.randn(npts)
3839
xyo = zip(xo, yo)
3940

4041
# Make a list of colors cycling through the rgbcmyk series.
@@ -45,7 +46,7 @@
4546
a = fig.add_subplot(2,2,1)
4647
col = collections.LineCollection([spiral], offsets=xyo,
4748
transOffset=a.transData)
48-
trans = transforms.Affine2D().scale(fig.dpi/72.0)
49+
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
4950
col.set_transform(trans) # the points to pixels transform
5051
# Note: the first argument to the collection initializer
5152
# must be a list of sequences of x,y tuples; we have only
@@ -112,7 +113,7 @@
112113
xx = (0.2 + (ym-yy)/ym)**2 * N.cos(yy-0.4) * 0.5
113114
segs = []
114115
for i in range(ncurves):
115-
xxx = xx + 0.02*N.random.randn(nverts)
116+
xxx = xx + 0.02*rs.randn(nverts)
116117
curve = zip(xxx, yy*100)
117118
segs.append(curve)
118119

lib/matplotlib/axes.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,15 +4603,8 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
46034603
rescale = np.sqrt(max(verts[:,0]**2+verts[:,1]**2))
46044604
verts /= rescale
46054605

4606-
scales = np.asarray(scales)
4607-
scales = np.sqrt(scales * self.figure.dpi / 72.)
4608-
if len(scales)==1:
4609-
verts = [scales[0]*verts]
4610-
else:
4611-
# todo -- make this nx friendly
4612-
verts = [verts*s for s in scales]
46134606
collection = mcoll.PolyCollection(
4614-
verts,
4607+
verts, scales,
46154608
facecolors = colors,
46164609
edgecolors = edgecolors,
46174610
linewidths = linewidths,

lib/matplotlib/collections.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,19 @@ def draw(self, renderer):
492492
renderer.close_group(self.__class__.__name__)
493493

494494
class PolyCollection(Collection):
495-
def __init__(self, verts, **kwargs):
495+
def __init__(self, verts, sizes = (1, ), **kwargs):
496496
"""
497497
verts is a sequence of ( verts0, verts1, ...) where verts_i is
498498
a sequence of xy tuples of vertices, or an equivalent
499499
numpy array of shape (nv,2).
500500
501+
sizes gives the area of the circle circumscribing the
502+
polygon in points^2
503+
501504
%(Collection)s
502505
"""
503506
Collection.__init__(self,**kwargs)
507+
self._sizes = sizes
504508
self.set_verts(verts)
505509
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
506510

@@ -511,6 +515,15 @@ def set_verts(self, verts):
511515
def get_paths(self):
512516
return self._paths
513517

518+
def draw(self, renderer):
519+
# sizes is the area of the circle circumscribing the polygon
520+
# in points^2
521+
self._transforms = [
522+
transforms.Affine2D().scale(
523+
(np.sqrt(x) * renderer.dpi / 72.0))
524+
for x in self._sizes]
525+
return Collection.draw(self, renderer)
526+
514527
class BrokenBarHCollection(PolyCollection):
515528
"""
516529
A colleciton of horizontal bars spanning yrange with a sequence of

0 commit comments

Comments
 (0)