Skip to content

Commit

Permalink
Use splines to render circles in scatter plots.
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=5641
  • Loading branch information
mdboom committed Jun 23, 2008
1 parent a8386f8 commit e8a8502
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2008-06-23 Use splines to render circles in scatter plots - MGD

===============================================================
2008-06-22 Released 0.98.1 at revision 5637

Expand Down
40 changes: 24 additions & 16 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4561,22 +4561,23 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
The marker can also be a tuple (*numsides*, *style*,
*angle*), which will create a custom, regular symbol.
*numsides*:
the number of sides
*numsides*:
the number of sides
*style*:
the style of the regular symbol:
*style*:
the style of the regular symbol:
===== ==================
Value Description
===== ==================
0 a regular polygon
1 a star-like symbol
2 an asterisk
===== ==================
===== ==================
Value Description
===== =========================================
0 a regular polygon
1 a star-like symbol
2 an asterisk
3 a circle (numsides and angle is ignored)
===== =========================================
*angle*:
the angle of rotation of the symbol
*angle*:
the angle of rotation of the symbol
Finally, *marker* can be (*verts*, 0): *verts* is a
sequence of (*x*, *y*) vertices for a custom scatter
Expand Down Expand Up @@ -4640,7 +4641,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,

syms = { # a dict from symbol to (numsides, angle)
's' : (4,math.pi/4.0,0), # square
'o' : (20,0,0), # circle
'o' : (20,3,0), # circle
'^' : (3,0,0), # triangle up
'>' : (3,math.pi/2.0,0), # triangle right
'v' : (3,math.pi,0), # triangle down
Expand Down Expand Up @@ -4748,9 +4749,16 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
offsets = zip(x,y),
transOffset = self.transData,
)
elif symstyle==3:
collection = mcoll.CircleCollection(
scales,
facecolors = colors,
edgecolors = edgecolors,
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
else:
# MGDTODO: This has dpi problems
# rescale verts
rescale = np.sqrt(max(verts[:,0]**2+verts[:,1]**2))
verts /= rescale

Expand Down
28 changes: 27 additions & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,32 @@ def get_color(self):
return self._edgecolors
get_colors = get_color # for compatibility with old versions

class CircleCollection(Collection):
"""
A collection of circles, drawn using splines.
"""
def __init__(self, sizes):
"""
*sizes*
Gives the area of the circle in points^2
%(Collection)s
"""
Collection.__init__(self,**kwargs)
self._sizes = sizes
self.set_transform(transforms.IdentityTransform())
self._paths = [mpath.Path.unit_circle()]

def draw(self, renderer):
# sizes is the area of the circle circumscribing the polygon
# in points^2
self._transforms = [
transforms.Affine2D().scale(
(np.sqrt(x) * renderer.dpi / 72.0) / np.sqrt(np.pi))
for x in self._sizes]
return Collection.draw(self, renderer)


class PatchCollection(Collection):
"""
A generic collection of patches.
Expand Down Expand Up @@ -870,6 +896,6 @@ def get_paths(self):

artist.kwdocd['Collection'] = patchstr = artist.kwdoc(Collection)
for k in ('QuadMesh', 'PolyCollection', 'BrokenBarHCollection', 'RegularPolyCollection',
'StarPolygonCollection'):
'StarPolygonCollection', 'PatchCollection', 'CircleCollection'):
artist.kwdocd[k] = patchstr
artist.kwdocd['LineCollection'] = artist.kwdoc(LineCollection)

0 comments on commit e8a8502

Please sign in to comment.