@@ -288,36 +288,66 @@ def __init__(self,
288288 sizes = (1 ,),
289289 ** kwargs ):
290290 """
291- Draw a regular polygon with numsides. sizes gives the area of
292- the circle circumscribing the regular polygon and rotation is
293- the rotation of the polygon in radians.
291+ Draw a regular polygon with numsides.
292+
293+ * dpi is the figure dpi instance, and is required to do the
294+ area scaling.
295+
296+ * numsides: the number of sides of the polygon
297+
298+ * sizes gives the area of the circle circumscribing the
299+ regular polygon in points^2
300+
301+ * rotation is the rotation of the polygon in radians
302+
303+ kwargs: See PatchCollection for more details
304+
305+ * offsets are a sequence of x,y tuples that give the centers of
306+ the polygon in data coordinates
307+
308+ * transOffset is the Transformation instance used to
309+ transform the centers onto the canvas.
310+
311+ Example: see examples/dynamic_collection.py for complete example
312+
313+ offsets = nx.mlab.rand(20,2)
314+ facecolors = [cm.jet(x) for x in nx.mlab.rand(20)]
315+ black = (0,0,0,1)
316+
317+ collection = RegularPolyCollection(
318+ fig.dpi,
319+ numsides=5, # a pentagon
320+ rotation=0,
321+ sizes=(50,),
322+ facecolors = facecolors,
323+ edgecolors = (black,),
324+ linewidths = (1,),
325+ offsets = offsets,
326+ transOffset = ax.transData,
327+ )
294328
295- offsets are a sequence of x,y tuples that give the centers of
296- the polygon in data coordinates, and transOffset is the
297- Transformation instance used to transform the centers onto the
298- canvas.
299329
300- dpi is the figure dpi instance, and is required to do the area
301- scaling.
302330 """
303331 PatchCollection .__init__ (self ,** kwargs )
304- self ._sizes = asarray ( sizes )
332+ self ._sizes = sizes
305333 self ._dpi = dpi
334+ self .numsides = numsides
335+ self .rotation = rotation
336+ self ._update_verts ()
306337
338+ def _update_verts (self ):
307339 r = 1.0 / math .sqrt (math .pi ) # unit area
308-
309- theta = (2 * math .pi / numsides )* arange (numsides ) + rotation
340+ theta = (2 * math .pi / self .numsides )* arange (self .numsides ) + self .rotation
310341 self ._verts = zip ( r * sin (theta ), r * cos (theta ) )
311342
312-
313-
314343 def draw (self , renderer ):
315344 if not self .get_visible (): return
316345 renderer .open_group ('regpolycollection' )
317346 self ._transform .freeze ()
318347 self ._transOffset .freeze ()
319348 self .update_scalarmappable ()
320- scales = sqrt (self ._sizes * self ._dpi .get ()/ 72.0 )
349+ self ._update_verts ()
350+ scales = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
321351
322352 if is_string_like (self ._edgecolors ) and self ._edgecolors == 'None' :
323353 self ._edgecolors = self ._facecolors
0 commit comments