Revision: 5047
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5047&view=rev
Author:   efiring
Date:     2008-04-18 13:11:03 -0700 (Fri, 18 Apr 2008)

Log Message:
-----------
Improve color handling in collections, fix scatter bug.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/collections.py
    trunk/matplotlib/lib/matplotlib/colors.py

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-04-18 15:20:03 UTC (rev 
5046)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-04-18 20:11:03 UTC (rev 
5047)
@@ -4134,7 +4134,7 @@
         """
         SCATTER(x, y, s=20, c='b', marker='o', cmap=None, norm=None,
             vmin=None, vmax=None, alpha=1.0, linewidths=None,
-            faceted=True, **kwargs)
+            verts=None, **kwargs)
         Supported function signatures:
 
             SCATTER(x, y, **kwargs)
@@ -4187,10 +4187,9 @@
             angle is 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 symbol.
+        vertices for a custom scatter symbol.  Alternatively, use the
+        kwarg combination marker=None,verts=verts.
 
-        s is a size argument in points squared.
-
         Any or all of x, y, s, and c may be masked arrays, in which
         case all masks will be combined and only unmasked points
         will be plotted.
@@ -4217,16 +4216,13 @@
             required by RegularPolyCollection -- see
             collections.RegularPolyCollection for details
 
-         * faceted: if True, will use the default edgecolor for the
-           markers.  If False, will set the edgecolors to be the same
-           as the facecolors.
-           This kwarg is deprecated;
-           please use the edgecolors kwarg instead:
-               shading='flat'    --> edgecolors='None'
-               shading='faceted  --> edgecolors=None
-           edgecolors also can be any mpl color or sequence of colors.
+           Optional kwargs control the Collection properties; in
+           particular:
 
-           Optional kwargs control the Collection properties:
+            edgecolors='none' : to plot faces with no outlines
+            facecolors='none' : to plot unfilled outlines
+
+           Here are the standard descriptions of all the Collection kwargs:
         %(Collection)s
 
         A Collection instance is returned
@@ -4270,8 +4266,12 @@
         else:
             scales = s
 
-        if faceted: edgecolors = None
-        else: edgecolors = 'None'
+        if faceted:
+            edgecolors = None
+        else:
+            edgecolors = 'none'
+            warnings.warn('''replace "faceted=False" with 
"edgecolors='none'"''',
+                           DeprecationWarning)   #2008/04/18
 
         sym = None
         symstyle = 0

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py      2008-04-18 15:20:03 UTC 
(rev 5046)
+++ trunk/matplotlib/lib/matplotlib/collections.py      2008-04-18 20:11:03 UTC 
(rev 5047)
@@ -77,21 +77,12 @@
         artist.Artist.__init__(self)
         cm.ScalarMappable.__init__(self, norm, cmap)
 
-        if facecolors is None: facecolors = mpl.rcParams['patch.facecolor']
-        if edgecolors is None: edgecolors = mpl.rcParams['patch.edgecolor']
-        if linewidths is None: linewidths = (mpl.rcParams['patch.linewidth'],)
-        if antialiaseds is None: antialiaseds = 
(mpl.rcParams['patch.antialiased'],)
-        self.set_linestyles(linestyles)
+        self.set_edgecolor(edgecolors)
+        self.set_facecolor(facecolors)
+        self.set_linewidth(linewidths)
+        self.set_linestyle(linestyles)
+        self.set_antialiased(antialiaseds)
 
-        self._facecolors  = _colors.colorConverter.to_rgba_array(facecolors)
-        if edgecolors == 'None':
-            self._edgecolors = self._facecolors
-            linewidths = (0,)
-        else:
-            self._edgecolors = _colors.colorConverter.to_rgba_array(edgecolors)
-        self._linewidths  = self._get_value(linewidths)
-        self._antialiaseds = self._get_value(antialiaseds)
-
         self._uniform_offsets = None
         self._offsets = npy.array([], npy.float_)
         if offsets is not None:
@@ -118,6 +109,17 @@
 
         raise TypeError('val must be a float or nonzero sequence of floats')
 
+    def _get_bool(self, val):
+        try: return (bool(val), )
+        except TypeError:
+            if cbook.iterable(val) and len(val):
+                try: bool(val[0])
+                except TypeError: pass # raise below
+                else: return val
+
+        raise TypeError('val must be a bool or nonzero sequence of them')
+
+
     def get_paths(self):
         raise NotImplementedError
 
@@ -219,6 +221,7 @@
 
         ACCEPTS: float or sequence of floats
         """
+        if lw is None: lw = mpl.rcParams['patch.linewidth']
         self._linewidths = self._get_value(lw)
     set_lw = set_linewidth = set_linewidths
 
@@ -263,6 +266,17 @@
         self._linestyles = dashes
     set_dashes = set_linestyle = set_linestyles
 
+    def set_antialiased(self, aa):
+        """
+        Set the antialiasing state for rendering.
+
+        ACCEPTS: Boolean or sequence of booleans
+        """
+        if aa is None:
+            aa = mpl.rcParams['patch.antialiased']
+        self._antialiaseds = self._get_bool(aa)
+    set_antialiaseds = set_antialiased
+
     def set_color(self, c):
         """
         Set both the edgecolor and the facecolor.
@@ -282,6 +296,7 @@
 
         ACCEPTS: matplotlib color arg or sequence of rgba tuples
         """
+        if c is None: c = mpl.rcParams['patch.facecolor']
         self._facecolors = _colors.colorConverter.to_rgba_array(c, self._alpha)
 
     set_facecolors = set_facecolor
@@ -298,16 +313,14 @@
 
         ACCEPTS: matplotlib color arg or sequence of rgba tuples
         """
-        if c == 'None':
-            self._linewidths = (0.0,)
-            self._edgecolors = npy.array([])
-        else:
-            self._edgecolors = _colors.colorConverter.to_rgba_array(c)
+        if c is None: c = mpl.rcParams['patch.edgecolor']
+        self._edgecolors = _colors.colorConverter.to_rgba_array(c, self._alpha)
+
     set_edgecolors = set_edgecolor
 
     def set_alpha(self, alpha):
         """
-        Set the alpha tranpancies of the collection.  Alpha must be
+        Set the alpha tranparencies of the collection.  Alpha must be
         a float.
 
         ACCEPTS: float
@@ -316,9 +329,14 @@
         except TypeError: raise TypeError('alpha must be a float')
         else:
             artist.Artist.set_alpha(self, alpha)
-            if len(self._facecolors):
+            try:
                 self._facecolors[:, 3] = alpha
-            self._edgecolors[:, 3] = alpha
+            except (AttributeError, TypeError, IndexError):
+                pass
+            try:
+                self._edgecolors[:, 3] = alpha
+            except (AttributeError, TypeError, IndexError):
+                pass
 
     def get_linewidths(self):
         return self._linewidths
@@ -334,7 +352,7 @@
         from scalar data
         """
         if self._A is None: return
-        if len(self._A.shape)>1:
+        if self._A.ndim > 1:
             raise ValueError('Collections can only map rank 1 arrays')
         if len(self._facecolors):
             self._facecolors = self.to_rgba(self._A, self._alpha)

Modified: trunk/matplotlib/lib/matplotlib/colors.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/colors.py   2008-04-18 15:20:03 UTC (rev 
5046)
+++ trunk/matplotlib/lib/matplotlib/colors.py   2008-04-18 20:11:03 UTC (rev 
5047)
@@ -314,8 +314,18 @@
         Accepts a single mpl color spec or a sequence of specs.
         If the sequence is a list or array, the items are changed in place,
         but an array copy is still returned.
+
+        Special case to handle "no color": if c is "none" (case-insensitive),
+        then an empty array will be returned.  Same for an empty list.
         """
         try:
+            if c.lower() == 'none':
+                return npy.zeros((0,4), dtype=npy.float_)
+        except AttributeError:
+            pass
+        if len(c) == 0:
+            return npy.zeros((0,4), dtype=npy.float_)
+        try:
             result = [self.to_rgba(c, alpha)]
         except ValueError:
             # If c is a list it must be maintained as the same list


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to