Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01bdca7

Browse files
committed
Improved scatter argument handling; a few cleanups
svn path=/trunk/matplotlib/; revision=3166
1 parent 1ca2279 commit 01bdca7

3 files changed

Lines changed: 34 additions & 31 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def delete_masked_points(*args):
6767
include arguments that can take string or array values, for
6868
example.
6969
70-
Array arguments must all have the same shape, and must
70+
Array arguments must have the same length; masked arguments must
7171
be one-dimensional.
7272
7373
Written as a helper for scatter, but may be more generally
@@ -79,7 +79,7 @@ def delete_masked_points(*args):
7979
mask = reduce(ma.mask_or, masks)
8080
margs = []
8181
for x in args:
82-
if shape(x) == shape(mask):
82+
if not is_string_like(x) and len(x) == len(mask):
8383
if (hasattr(x, 'get_compressed_copy')):
8484
compressed_x = x.get_compressed_copy(mask)
8585
else:
@@ -3683,21 +3683,27 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
36833683
faceted=True, **kwargs)
36843684
Supported function signatures:
36853685
3686-
SCATTER(x, y) - make a scatter plot of x vs y
3686+
SCATTER(x, y, **kwargs)
3687+
SCATTER(x, y, s, **kwargs)
3688+
SCATTER(x, y, s, c, **kwargs)
36873689
3688-
SCATTER(x, y, s) - make a scatter plot of x vs y with size in area
3689-
given by s
3690+
Make a scatter plot of x versus y, where x, y are 1-D sequences
3691+
of the same length, N.
36903692
3691-
SCATTER(x, y, s, c) - make a scatter plot of x vs y with size in area
3692-
given by s and colors given by c
3693+
Arguments s and c can also be given as kwargs; this is encouraged
3694+
for readability.
36933695
3694-
SCATTER(x, y, s, c, **kwargs) - control colormapping and scaling
3695-
with keyword args; see below
3696+
s is a size in points^2. It is a scalar
3697+
or an array of the same length as x and y.
36963698
3697-
Make a scatter plot of x versus y. s is a size in points^2 a scalar
3698-
or an array of the same length as x or y. c is a color and can be a
3699-
single color format string or a length(x) array of intensities which
3700-
will be mapped by the matplotlib.colors.colormap instance cmap
3699+
c is a color and can be a single color format string,
3700+
or a sequence of color specifications of length N,
3701+
or a sequence of N numbers to be mapped to colors
3702+
using the cmap and norm specified via kwargs (see below).
3703+
Note that c should not be a single numeric RGB or RGBA
3704+
sequence because that is indistinguishable from an array
3705+
of values to be colormapped. c can be a 2-D array in which
3706+
the rows are RGB or RGBA, however.
37013707
37023708
The marker can be one of
37033709
@@ -3772,8 +3778,13 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
37723778

37733779
# The inherent ambiguity is resolved in favor of color
37743780
# mapping, not interpretation as rgb or rgba.
3775-
if not is_string_like(c) and iterable(c) and len(c)==len(x):
3776-
colors = None # use cmap, norm after collection is created
3781+
3782+
if not is_string_like(c):
3783+
sh = shape(c)
3784+
if len(sh) == 1 and sh[0] == len(x):
3785+
colors = None # use cmap, norm after collection is created
3786+
else:
3787+
colors = colorConverter.to_rgba_list(c, alpha)
37773788
else:
37783789
colors = colorConverter.to_rgba_list(c, alpha)
37793790

lib/matplotlib/cm.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ def to_rgba(self, x, alpha=1.0):
6161
def set_array(self, A):
6262
'Set the image array from numeric/numarray A'
6363
self._A = A
64-
#from numerix import typecode, typecodes
65-
#if typecode(A) in typecodes['Float']:
66-
# self._A = A.astype(nx.Float32)
67-
#else:
68-
# self._A = A.astype(nx.Int16)
6964

7065
def get_array(self):
7166
'Return the array'

lib/matplotlib/image.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,13 @@ def set_data(self, A, shape=None):
214214
"""
215215
Set the image array
216216
217-
ACCEPTS: numeric/numarray/PIL Image A"""
217+
ACCEPTS: numpy/PIL Image A"""
218218
# check if data is PIL Image without importing Image
219-
if hasattr(A,'getpixel'): X = pil_to_array(A)
220-
else: X = ma.asarray(A) # assume array
221-
222-
if (typecode(X) != UInt8
223-
or len(X.shape) != 3
224-
or X.shape[2] > 4
225-
or X.shape[2] < 3):
226-
cm.ScalarMappable.set_array(self, X)
219+
if hasattr(A,'getpixel'):
220+
X = pil_to_array(A)
227221
else:
228-
self._A = X
222+
X = ma.asarray(A) # assume array
223+
self._A = X
229224

230225
self._imcache =None
231226

@@ -234,7 +229,9 @@ def set_array(self, A):
234229
retained for backwards compatibility - use set_data instead
235230
236231
ACCEPTS: numeric/numarray/PIL Image A"""
237-
232+
# This also needs to be here to override the inherited
233+
# cm.ScalarMappable.set_array method so it is not invoked
234+
# by mistake.
238235

239236
self.set_data(A)
240237

0 commit comments

Comments
 (0)