matplotlib.pyplot.scatter#
- matplotlib.pyplot.scatter(x,y,s=None,c=None,*,marker=None,cmap=None,norm=None,vmin=None,vmax=None,alpha=None,linewidths=None,edgecolors=None,colorizer=None,plotnonfinite=False,data=None,**kwargs)[source]#
A scatter plot ofy vs.x with varying marker size and/or color.
- Parameters:
- x, yfloat or array-like, shape (n, )
The data positions.
- sfloat or array-like, shape (n, ), optional
The marker size in points**2 (typographic points are 1/72 in.).Default is
rcParams['lines.markersize']**2
.The linewidth and edgecolor can visually interact with the markersize, and can lead to artifacts if the marker size is smaller thanthe linewidth.
If the linewidth is greater than 0 and the edgecolor is anythingbut'none', then the effective size of the marker will beincreased by half the linewidth because the stroke will be centeredon the edge of the shape.
To eliminate the marker edge either setlinewidth=0 oredgecolor='none'.
- carray-like or list ofcolor orcolor, optional
The marker colors. Possible values:
A scalar or sequence of n numbers to be mapped to colors usingcmap andnorm.
A 2D array in which the rows are RGB or RGBA.
A sequence of colors of length n.
A single color format string.
Note thatc should not be a single numeric RGB or RGBA sequencebecause that is indistinguishable from an array of values to becolormapped. If you want to specify the same RGB or RGBA value forall points, use a 2D array with a single row. Otherwise,value-matching will have precedence in case of a size matching withx andy.
If you wish to specify a single color for all pointsprefer thecolor keyword argument.
Defaults to
None
. In that case the marker color is determinedby the value ofcolor,facecolor orfacecolors. In casethose are not specified orNone
, the marker color is determinedby the next color of theAxes
' current "shape and fill" colorcycle. This cycle defaults torcParams["axes.prop_cycle"]
(default:cycler('color',[(0.12156862745098039,0.4666666666666667,0.7058823529411765),(1.0,0.4980392156862745,0.054901960784313725),(0.17254901960784313,0.6274509803921569,0.17254901960784313),(0.8392156862745098,0.15294117647058825,0.1568627450980392),(0.5803921568627451,0.403921568627451,0.7411764705882353),(0.5490196078431373,0.33725490196078434,0.29411764705882354),(0.8901960784313725,0.4666666666666667,0.7607843137254902),(0.4980392156862745,0.4980392156862745,0.4980392156862745),(0.7372549019607844,0.7411764705882353,0.13333333333333333),(0.09019607843137255,0.7450980392156863,0.8117647058823529)])
).- marker
MarkerStyle
, default:rcParams["scatter.marker"]
(default:'o'
) The marker style.marker can be either an instance of the classor the text shorthand for a particular marker.See
matplotlib.markers
for more information about markerstyles.- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to map scalar datato colors.
This parameter is ignored ifc is RGB(A).
- normstr or
Normalize
, optional The normalization method used to scale scalar data to the [0, 1] rangebefore mapping to colors usingcmap. By default, a linear scaling isused, mapping the lowest value to 0 and the highest to 1.
If given, this can be one of the following:
An instance of
Normalize
or one of its subclasses(seeColormap normalization).A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For alist of available scales, call
matplotlib.scale.get_scale_names()
.In that case, a suitableNormalize
subclass is dynamically generatedand instantiated.
This parameter is ignored ifc is RGB(A).
- vmin, vmaxfloat, optional
When using scalar data and no explicitnorm,vmin andvmax definethe data range that the colormap covers. By default, the colormap coversthe complete value range of the supplied data. It is an error to usevmin/vmax when anorm instance is given (but using a
str
normname together withvmin/vmax is acceptable).This parameter is ignored ifc is RGB(A).
- alphafloat, default: None
The alpha blending value, between 0 (transparent) and 1 (opaque).
- linewidthsfloat or array-like, default:
rcParams["lines.linewidth"]
(default:1.5
) The linewidth of the marker edges. Note: The defaultedgecolorsis 'face'. You may want to change this as well.
- edgecolors{'face', 'none',None} orcolor or list ofcolor, default:
rcParams["scatter.edgecolors"]
(default:'face'
) The edge color of the marker. Possible values:
'face': The edge color will always be the same as the face color.
'none': No patch boundary will be drawn.
A color or sequence of colors.
For non-filled markers,edgecolors is ignored. Instead, the coloris determined like with 'face', i.e. fromc,colors, orfacecolors.
- colorizer
Colorizer
or None, default: None The Colorizer object used to map color to data. If None, a Colorizerobject is created from anorm andcmap.
This parameter is ignored ifc is RGB(A).
- plotnonfinitebool, default: False
Whether to plot points with nonfinitec (i.e.
inf
,-inf
ornan
). IfTrue
the points are drawn with thebadcolormap color (seeColormap.set_bad
).
- Returns:
- Other Parameters:
- dataindexable object, optional
If given, the following parameters also accept a string
s
, which isinterpreted asdata[s]
ifs
is a key indata
:x,y,s,linewidths,edgecolors,c,facecolor,facecolors,color
- **kwargs
PathCollection
properties Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
array-like or float or None
bool
bool or list of bools
array-like or None
CapStyle
or {'butt', 'projecting', 'round'}(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Nonecolor or list of RGBA tuples
edgecolor
orec
oredgecolors
facecolor
orfacecolors
orfc
str
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
unknown
bool
JoinStyle
or {'miter', 'round', 'bevel'}object
linestyle
ordashes
orlinestyles
orls
str or tuple or list thereof
linewidth
orlinewidths
orlw
float or list of floats
bool
Normalize
or str or None(N, 2) or (2,) array-like
list of
AbstractPathEffect
unknown
None or bool or float or callable
float
bool
numpy.ndarray
or None(scale: float, length: float, randomness: float)
bool or None
str
list of str or None
bool
float
See also
plot
To plot scatter plots when markers are identical in size and color.
Notes
Note
This is thepyplot wrapper for
axes.Axes.scatter
.The
plot
function will be faster for scatterplots where markersdon't vary in size or color.Any or all ofx,y,s, andc may be masked arrays, in whichcase all masks will be combined and only unmasked points will beplotted.
Fundamentally, scatter works with 1D arrays;x,y,s, andcmay be input as N-D arrays, but within scatter they will beflattened. The exception isc, which will be flattened only if itssize matches the size ofx andy.