@@ -3509,9 +3509,10 @@ def dopatch(xs, ys, **kwargs):
3509
3509
medians = medians , fliers = fliers , means = means )
3510
3510
3511
3511
@docstring .dedent_interpd
3512
- def scatter (self , x , y , s = 20 , c = 'b' , marker = 'o' , cmap = None , norm = None ,
3512
+ def scatter (self , x , y , s = 20 , c = None , marker = 'o' , cmap = None , norm = None ,
3513
3513
vmin = None , vmax = None , alpha = None , linewidths = None ,
3514
- verts = None , ** kwargs ):
3514
+ verts = None , edgecolors = None ,
3515
+ ** kwargs ):
3515
3516
"""
3516
3517
Make a scatter plot of x vs y, where x and y are sequence like objects
3517
3518
of the same lengths.
@@ -3531,11 +3532,14 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
3531
3532
(see below). Note that `c` should not be a single numeric RGB or
3532
3533
RGBA sequence because that is indistinguishable from an array of
3533
3534
values to be colormapped. `c` can be a 2-D array in which the
3534
- rows are RGB or RGBA, however.
3535
+ rows are RGB or RGBA, however, including the case of a single
3536
+ row to specify the same color for all points.
3535
3537
3536
3538
marker : `~matplotlib.markers.MarkerStyle`, optional, default: 'o'
3537
3539
See `~matplotlib.markers` for more information on the different
3538
- styles of markers scatter supports.
3540
+ styles of markers scatter supports. `marker` can be either
3541
+ an instance of the class or the text shorthand for a particular
3542
+ marker.
3539
3543
3540
3544
cmap : `~matplotlib.colors.Colormap`, optional, default: None
3541
3545
A `~matplotlib.colors.Colormap` instance or registered name.
@@ -3557,10 +3561,14 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
3557
3561
The alpha blending value, between 0 (transparent) and 1 (opaque)
3558
3562
3559
3563
linewidths : scalar or array_like, optional, default: None
3560
- If None, defaults to (lines.linewidth,). Note that this is a
3561
- tuple, and if you set the linewidths argument you must set it as a
3562
- sequence of floats, as required by
3563
- `~matplotlib.collections.RegularPolyCollection`.
3564
+ If None, defaults to (lines.linewidth,).
3565
+
3566
+ edgecolors : color or sequence of color, optional, default: None
3567
+ If None, defaults to (patch.edgecolor).
3568
+ If 'face', the edge color will always be the same as
3569
+ the face color. If it is 'none', the patch boundary will not
3570
+ be drawn. For non-filled markers, the `edgecolors` kwarg
3571
+ is ignored; color is determined by `c`.
3564
3572
3565
3573
Returns
3566
3574
-------
@@ -3585,6 +3593,32 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
3585
3593
if not self ._hold :
3586
3594
self .cla ()
3587
3595
3596
+ # Process **kwargs to handle aliases, conflicts with explicit kwargs:
3597
+
3598
+ facecolors = None
3599
+ ec = kwargs .pop ('edgecolor' , None )
3600
+ if ec is not None :
3601
+ edgecolors = ec
3602
+ fc = kwargs .pop ('facecolor' , None )
3603
+ if fc is not None :
3604
+ facecolors = fc
3605
+ fc = kwargs .pop ('facecolors' , None )
3606
+ if fc is not None :
3607
+ facecolors = fc
3608
+ # 'color' should be deprecated in scatter, or clearly defined;
3609
+ # since it isn't, I am giving it low priority.
3610
+ co = kwargs .pop ('color' , None )
3611
+ if co is not None :
3612
+ if edgecolors is None :
3613
+ edgecolors = co
3614
+ if facecolors is None :
3615
+ facecolors = co
3616
+ if c is None :
3617
+ if facecolors is not None :
3618
+ c = facecolors
3619
+ else :
3620
+ c = 'b' # the original default
3621
+
3588
3622
self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
3589
3623
x = self .convert_xunits (x )
3590
3624
y = self .convert_yunits (y )
@@ -3598,43 +3632,41 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
3598
3632
3599
3633
s = np .ma .ravel (s ) # This doesn't have to match x, y in size.
3600
3634
3601
- c_is_stringy = is_string_like (c ) or is_sequence_of_strings (c )
3602
- if not c_is_stringy :
3603
- c = np .asanyarray (c )
3604
- if c .size == x .size :
3605
- c = np .ma .ravel (c )
3635
+ # After this block, c_array will be None unless
3636
+ # c is an array for mapping. The potential ambiguity
3637
+ # with a sequence of 3 or 4 numbers is resolved in
3638
+ # favor mapping, not rgb or rgba.
3639
+ try :
3640
+ c_array = np .asanyarray (c , dtype = float )
3641
+ if c_array .shape == x .shape :
3642
+ c = np .ma .ravel (c_array )
3643
+ else :
3644
+ # Wrong shape; it must not be intended for mapping.
3645
+ c_array = None
3646
+ except ValueError :
3647
+ # Failed to make a floating-point array; c must be color specs.
3648
+ c_array = None
3649
+
3650
+ if c_array is None :
3651
+ colors = c # must be acceptable as PathCollection facecolors
3652
+ else :
3653
+ colors = None # use cmap, norm after collection is created
3606
3654
3655
+ # c will be unchanged unless it is the same length as x:
3607
3656
x , y , s , c = cbook .delete_masked_points (x , y , s , c )
3608
3657
3609
3658
scales = s # Renamed for readability below.
3610
3659
3611
- if c_is_stringy :
3612
- colors = mcolors .colorConverter .to_rgba_array (c , alpha )
3613
- else :
3614
- # The inherent ambiguity is resolved in favor of color
3615
- # mapping, not interpretation as rgb or rgba:
3616
- if c .size == x .size :
3617
- colors = None # use cmap, norm after collection is created
3618
- else :
3619
- colors = mcolors .colorConverter .to_rgba_array (c , alpha )
3620
-
3621
- faceted = kwargs .pop ('faceted' , None )
3622
- edgecolors = kwargs .get ('edgecolors' , None )
3623
- if faceted is not None :
3624
- cbook .warn_deprecated (
3625
- '1.2' , name = 'faceted' , alternative = 'edgecolor' ,
3626
- obj_type = 'option' )
3627
- if faceted :
3628
- edgecolors = None
3629
- else :
3630
- edgecolors = 'none'
3631
-
3632
3660
# to be API compatible
3633
3661
if marker is None and not (verts is None ):
3634
3662
marker = (verts , 0 )
3635
3663
verts = None
3636
3664
3637
- marker_obj = mmarkers .MarkerStyle (marker )
3665
+ if isinstance (marker , mmarkers .MarkerStyle ):
3666
+ marker_obj = marker
3667
+ else :
3668
+ marker_obj = mmarkers .MarkerStyle (marker )
3669
+
3638
3670
path = marker_obj .get_path ().transformed (
3639
3671
marker_obj .get_transform ())
3640
3672
if not marker_obj .is_filled ():
@@ -3649,9 +3681,9 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
3649
3681
linewidths = linewidths ,
3650
3682
offsets = offsets ,
3651
3683
transOffset = kwargs .pop ('transform' , self .transData ),
3684
+ alpha = alpha
3652
3685
)
3653
3686
collection .set_transform (mtransforms .IdentityTransform ())
3654
- collection .set_alpha (alpha )
3655
3687
collection .update (kwargs )
3656
3688
3657
3689
if colors is None :
0 commit comments