From: <ef...@us...> - 2008-11-11 06:53:00
|
Revision: 6387 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6387&view=rev Author: efiring Date: 2008-11-11 06:52:52 +0000 (Tue, 11 Nov 2008) Log Message: ----------- Fix handling of c kwarg in scatter, with array of strings; modification of patch by Ryan May. The fix involves making cbook.is_string_like handle variables of type numpy.string_. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/cbook.py trunk/matplotlib/lib/matplotlib/colors.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-11-10 22:41:27 UTC (rev 6386) +++ trunk/matplotlib/CHANGELOG 2008-11-11 06:52:52 UTC (rev 6387) @@ -1,4 +1,8 @@ -2008-11-09 Fix a possible EINTR problem in dviread, which might help +2008-11-10 Fix handling of c kwarg by scatter; generalize + is_string_like to accept numpy and numpy.ma string + array scalars. - RM and EF + +2008-11-09 Fix a possible EINTR problem in dviread, which might help when saving pdf files from the qt backend. - JKS 2008-10-24 Added Jae Joon's fancy arrow, box and annotation Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-11-10 22:41:27 UTC (rev 6386) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-11-11 06:52:52 UTC (rev 6387) @@ -4927,17 +4927,17 @@ x, y, s, c = cbook.delete_masked_points(x, y, s, c) - # The inherent ambiguity is resolved in favor of color - # mapping, not interpretation as rgb or rgba. - if not is_string_like(c): + if is_string_like(c) or cbook.is_sequence_of_strings(c): + colors = mcolors.colorConverter.to_rgba_array(c, alpha) + else: sh = np.shape(c) + # The inherent ambiguity is resolved in favor of color + # mapping, not interpretation as rgb or rgba: if len(sh) == 1 and sh[0] == len(x): colors = None # use cmap, norm after collection is created else: colors = mcolors.colorConverter.to_rgba_array(c, alpha) - else: - colors = mcolors.colorConverter.to_rgba_array(c, alpha) if not iterable(s): scales = (s,) Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-11-10 22:41:27 UTC (rev 6386) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-11-11 06:52:52 UTC (rev 6387) @@ -266,8 +266,14 @@ def is_string_like(obj): - 'return true if *obj* looks like a string' - if hasattr(obj, 'shape'): return False + 'Return True if *obj* looks like a string' + if isinstance(obj, (str, unicode)): return True + # numpy strings are subclass of str, ma strings are not + if ma.isMaskedArray(obj): + if obj.ndim == 0 and obj.dtype.kind in 'SU': + return True + else: + return False try: obj + '' except (TypeError, ValueError): return False return True Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2008-11-10 22:41:27 UTC (rev 6386) +++ trunk/matplotlib/lib/matplotlib/colors.py 2008-11-11 06:52:52 UTC (rev 6387) @@ -320,11 +320,9 @@ def to_rgba_array(self, c, alpha=None): """ - Returns an Numpy array of *RGBA* tuples. + Returns a numpy array of *RGBA* tuples. 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. @@ -339,11 +337,8 @@ try: result = np.array([self.to_rgba(c, alpha)], dtype=np.float_) except ValueError: - # If c is a list it must be maintained as the same list - # with modified items so that items can be appended to - # it. This is needed for examples/dynamic_collections.py. if isinstance(c, np.ndarray): - if len(c.shape) != 2: + if c.ndim != 2 and c.dtype.kind not in 'SU': raise ValueError("Color array must be two-dimensional") result = np.zeros((len(c), 4)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |