@@ -4133,7 +4133,7 @@ def dopatch(xs, ys, **kwargs):
4133
4133
medians = medians , fliers = fliers , means = means )
4134
4134
4135
4135
@staticmethod
4136
- def _parse_scatter_color_args (c , edgecolors , kwargs , xshape , yshape ,
4136
+ def _parse_scatter_color_args (c , edgecolors , kwargs , xsize ,
4137
4137
get_next_color_func ):
4138
4138
"""
4139
4139
Helper function to process color related arguments of `.Axes.scatter`.
@@ -4163,8 +4163,8 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
4163
4163
Additional kwargs. If these keys exist, we pop and process them:
4164
4164
'facecolors', 'facecolor', 'edgecolor', 'color'
4165
4165
Note: The dict is modified by this function.
4166
- xshape, yshape : tuple of int
4167
- The shape of the x and y arrays passed to `.Axes.scatter`.
4166
+ xsize : int
4167
+ The size of the x and y arrays passed to `.Axes.scatter`.
4168
4168
get_next_color_func : callable
4169
4169
A callable that returns a color. This color is used as facecolor
4170
4170
if no other color is provided.
@@ -4187,9 +4187,6 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
4187
4187
The edgecolor specification.
4188
4188
4189
4189
"""
4190
- xsize = functools .reduce (operator .mul , xshape , 1 )
4191
- ysize = functools .reduce (operator .mul , yshape , 1 )
4192
-
4193
4190
facecolors = kwargs .pop ('facecolors' , None )
4194
4191
facecolors = kwargs .pop ('facecolor' , facecolors )
4195
4192
edgecolors = kwargs .pop ('edgecolor' , edgecolors )
@@ -4241,9 +4238,9 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
4241
4238
else :
4242
4239
try : # First, does 'c' look suitable for value-mapping?
4243
4240
c_array = np .asanyarray (c , dtype = float )
4244
- n_elem = c_array .shape [ 0 ]
4245
- if c_array . shape in [ xshape , yshape ] :
4246
- c = np . ma . ravel (c_array )
4241
+ n_elem = c_array .size
4242
+ if n_elem == xsize :
4243
+ c = c_array . ravel ()
4247
4244
else :
4248
4245
if c_array .shape in ((3 ,), (4 ,)):
4249
4246
_log .warning (
@@ -4263,18 +4260,17 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
4263
4260
try : # Then is 'c' acceptable as PathCollection facecolors?
4264
4261
colors = mcolors .to_rgba_array (c )
4265
4262
n_elem = colors .shape [0 ]
4266
- if colors .shape [0 ] not in (0 , 1 , xsize , ysize ):
4263
+ if colors .shape [0 ] not in (0 , 1 , xsize ):
4267
4264
8000
# NB: remember that a single color is also acceptable.
4268
4265
# Besides *colors* will be an empty array if c == 'none'.
4269
4266
valid_shape = False
4270
4267
raise ValueError
4271
- except ValueError :
4268
+ except ( ValueError , TypeError ) :
4272
4269
if not valid_shape : # but at least one conversion succeeded.
4273
4270
raise ValueError (
4274
4271
"'c' argument has {nc} elements, which is not "
4275
- "acceptable for use with 'x' with size {xs}, "
4276
- "'y' with size {ys}."
4277
- .format (nc = n_elem , xs = xsize , ys = ysize )
4272
+ "acceptable for use with 'x' and 'y' with size {xs}."
4273
+ .format (nc = n_elem , xs = xsize )
4278
4274
)
4279
4275
else :
4280
4276
# Both the mapping *and* the RGBA conversion failed: pretty
@@ -4301,7 +4297,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4301
4297
4302
4298
Parameters
4303
4299
----------
4304
- x, y : array_like, shape (n, )
4300
+ x, y : scalar or array_like, shape (n, )
4305
4301
The data positions.
4306
4302
4307
4303
s : scalar or array_like, shape (n, ), optional
@@ -4313,8 +4309,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4313
4309
4314
4310
- A single color format string.
4315
4311
- A sequence of color specifications of length n.
4316
- - A sequence of n numbers to be mapped to colors using *cmap* and
4317
- *norm*.
4312
+ - A scalar or sequence of n numbers to be mapped to colors using
4313
+ *cmap* and * norm*.
4318
4314
- A 2-D array in which the rows are RGB or RGBA.
4319
4315
4320
4316
Note that *c* should not be a single numeric RGB or RGBA sequence
@@ -4403,7 +4399,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4403
4399
plotted.
4404
4400
4405
4401
* Fundamentally, scatter works with 1-D arrays; *x*, *y*, *s*, and *c*
4406
- may be input as 2 -D arrays, but within scatter they will be
4402
+ may be input as N -D arrays, but within scatter they will be
4407
4403
flattened. The exception is *c*, which will be flattened only if its
4408
4404
size matches the size of *x* and *y*.
4409
4405
@@ -4416,7 +4412,6 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4416
4412
4417
4413
# np.ma.ravel yields an ndarray, not a masked array,
4418
4414
# unless its argument is a masked array.
4419
- xshape , yshape = np .shape (x ), np .shape (y )
4420
4415
x = np .ma .ravel (x )
4421
4416
y = np .ma .ravel (y )
4422
4417
if x .size != y .size :
@@ -4429,7 +4424,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4429
4424
4430
4425
c , colors , edgecolors = \
4431
4426
self ._parse_scatter_color_args (
4432
- c , edgecolors , kwargs , xshape , yshape ,
4427
+ c , edgecolors , kwargs , x . size ,
4433
4428
get_next_color_func = self ._get_patches_for_fill .get_next_color )
4434
4429
4435
4430
if plotnonfinite and colors is None :
0 commit comments