John Hunter wrote:
>>>>>> "Manuel" == Manuel Metz <[EMAIL PROTECTED]> writes:
> 
>     Manuel> Argh - okay - this is a mistranslation from german to
>     Manuel> english - sorry. I wanted to say "starlike". So probably
>     Manuel> StarlikeRegularPolygon is a better name...
> 
> OK, I see.  Perhaps we should just call it a StarPolygonCollection
> http://en.wikipedia.org/wiki/Star_polygon

I've done that.

> Also, in your patch, unless I am missing something, it looks like you
> could simply do something like
> 
>         scale = 0.5/math.sqrt(math.pi)  
>         r = scale*ones(self.numsides*2)
> 
> rather than
> 
> +        r = 1.0/math.sqrt(math.pi)  # unit area
> +        r = asarray( [r]*(self.numsides*2) ) 
> +        for i in xrange(1,len(r),2):
> +            r[i] *= 0.5
> 
> Ie, do everything in numerix, rather than in python.

There is a subtle but essential difference ;-) :
        for i in xrange(1,len(r), 2 )
                                 ^^^
, i.e. every second value gets rescaled. But there is probably a more
"pythonic" way to do that:

        r = 1.0/math.sqrt(math.pi)  # unit area
        r = asarray( [r,0.5*r]*self.numsides )

I'm not aware of a better way to do this with numerix :-(

The patch against the latest svn revision (2810) is attached.

Manuel

> When you get all of this incorporated, if you could send one patch
> against svn that includes all of the changes I'll check it in (if
> noone else has any corrections or comments).
> 
> Thanks again,
> JDH
Index: axes.py
===================================================================
--- axes.py	(revision 2810)
+++ axes.py	(working copy)
@@ -15,7 +15,8 @@
 from axis import XAxis, YAxis
 from cbook import iterable, is_string_like, flatten, enumerate, \
      allequal, dict_delall, popd, popall, silent_list
-from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh
+from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh, \
+     StarPolygonCollection
 from colors import colorConverter, normalize, Colormap, \
         LinearSegmentedColormap, looks_like_color, is_color_like
 import cm
@@ -1211,7 +1212,7 @@
         if xmax is None and hasattr(xmin,'__len__'):
             xmin,xmax = xmin
 
-	old_xmin,old_xmax = self.get_xlim()
+        old_xmin,old_xmax = self.get_xlim()
         if xmin is None: xmin = old_xmin
         if xmax is None: xmax = old_xmax
 
@@ -1223,7 +1224,7 @@
             xmin -= 1e-38
             xmax += 1e-38
 
-	self.viewLim.intervalx().set_bounds(xmin, xmax)
+        self.viewLim.intervalx().set_bounds(xmin, xmax)
         if emit: self._send_xlim_event()
         return xmin, xmax
 
@@ -1324,7 +1325,7 @@
         if ymax is None and hasattr(ymin,'__len__'):
             ymin,ymax = ymin
 
-	old_ymin,old_ymax = self.get_ylim()
+        old_ymin,old_ymax = self.get_ylim()
         if ymin is None: ymin = old_ymin
         if ymax is None: ymax = old_ymax
 
@@ -3100,10 +3101,9 @@
             'h' : hexagon
             '8' : octagon
 
+        If marker is None and verts is not None, verts is a sequence
+        of (x,y) vertices for a custom scatter symbol.
 
-        if marker is None and verts is not None, verts is a sequence
-        of (x,y) vertices for a custom scatter symbol.  The
-
         s is a size argument in points squared.
 
         Any or all of x, y, s, and c may be masked arrays, in which
@@ -3171,26 +3171,74 @@
         if faceted: edgecolors = None
         else: edgecolors = 'None'
 
-        sym = syms.get(marker)
-        if sym is None and verts is None:
-            raise ValueError('Unknown marker symbol to scatter')
-
+        sym = None
+        starlike = False
+        
+        if isinstance(marker, str) or isinstance(marker, unicode):
+            # the standard way to define symbols using a string character
+            sym = syms.get(marker)
+            if sym is None and verts is None:
+                raise ValueError('Unknown marker symbol to scatter')
+            numsides, rotation = syms[marker]
+        
+        # to be API compatible
+        if sym is None and not (verts is None):
+            marker = (verts, 0)
+            verts = None
+        
+        if isinstance(marker, tuple) or isinstance(marker, list):
+            # accept marker to be:
+            #    (numsides, style, [angle])
+            # or
+            #    (verts[], style, [angle])
+            
+            if len(marker)<2 or len(marker)>3:
+                raise ValueError('Cannot create markersymbol from marker')
+            
+            if isinstance(marker[0], int) or isinstance(marker[0], long):
+                # (numsides, style, [angle])
+                
+                if len(marker)==2:
+                    numsides, rotation = marker[0], math.pi/4.
+                elif len(marker)==3:
+                    numsides, rotation = marker[0], marker[2]
+                sym = True
+                
+                if marker[1]==1:
+                    # starlike symbol, everthing else is interpreted as solid symbol
+                    starlike = True
+            
+            else:
+                verts = asarray(marker[0])
+                
         if sym is not None:
-            numsides, rotation = syms[marker]
-            collection = RegularPolyCollection(
-                self.figure.dpi,
-                numsides, rotation, scales,
-                facecolors = colors,
-                edgecolors = edgecolors,
-                linewidths = linewidths,
-                offsets = zip(x,y),
-                transOffset = self.transData,
-                )
+            if not starlike:
+                collection = RegularPolyCollection(
+                    self.figure.dpi,
+                    numsides, rotation, scales,
+                    facecolors = colors,
+                    edgecolors = edgecolors,
+                    linewidths = linewidths,
+                    offsets = zip(x,y),
+                    transOffset = self.transData,
+                    )
+            else:
+                collection = StarPolygonCollection(
+                    self.figure.dpi,
+                    numsides, rotation, scales,
+                    facecolors = colors,
+                    edgecolors = edgecolors,
+                    linewidths = linewidths,
+                    offsets = zip(x,y),
+                    transOffset = self.transData,
+                    )
         else:
-            verts = asarray(verts)
-            # hmm, the scaling is whacked -- how do we want to scale with custom verts?
+            # rescale verts
+            rescale = sqrt(max(verts[:,0]**2+verts[:,1]**2))
+            verts /= rescale
+            
             scales = asarray(scales)
-            #scales = sqrt(scales * self.figure.dpi.get() / 72.)
+            scales = sqrt(scales * self.figure.dpi.get() / 72.)
             if len(scales)==1:
                 verts = [scales[0]*verts]
             else:
Index: collections.py
===================================================================
--- collections.py	(revision 2810)
+++ collections.py	(working copy)
@@ -293,7 +293,7 @@
         * dpi is the figure dpi instance, and is required to do the
           area scaling.
 
-        * numsides: the number of sides of the  polygon
+        * numsides: the number of sides of the polygon
 
         * sizes gives the area of the circle circumscribing the
           regular polygon in points^2
@@ -374,6 +374,42 @@
         raise NotImplementedError('Vertices in data coordinates are calculated\n'
                 + 'only with offsets and only if _transOffset == dataTrans.')
 
+class StarPolygonCollection(RegularPolyCollection):
+    def __init__(self,
+                 dpi,
+                 numsides,
+                 rotation = 0 ,
+                 sizes = (1,),
+                 **kwargs):
+        """
+        Draw a regular star like Polygone with numsides.
+        
+        * dpi is the figure dpi instance, and is required to do the
+          area scaling.
+
+        * numsides: the number of sides of the polygon
+
+        * sizes gives the area of the circle circumscribing the
+          regular polygon in points^2
+
+        * rotation is the rotation of the polygon in radians
+
+        kwargs: See PatchCollection for more details
+
+          * offsets are a sequence of x,y tuples that give the centers of
+            the polygon in data coordinates
+
+          * transOffset is the Transformation instance used to
+            transform the centers onto the canvas.
+        """
+        RegularPolyCollection.__init__(self, dpi, numsides, rotation, sizes, **kwargs)
+    
+    def _update_verts(self):
+        r = 1.0/math.sqrt(math.pi)  # unit area
+        r = asarray( [r,0.5*r]*self.numsides ) 
+        theta  = (2.*math.pi/(2*self.numsides))*arange(2*self.numsides) + self.rotation
+        self._verts = zip( r*sin(theta), r*cos(theta) )
+
 class LineCollection(Collection, ScalarMappable):
     """
     All parameters must be sequences.  The property of the ith line
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to