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 isrcParams['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 toNone. 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)])).

markerMarkerStyle, 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.Seematplotlib.markers for more information about markerstyles.

cmapstr orColormap, 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 orNormalize, 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:

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 astrnormname 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.

colorizerColorizer 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,-infornan). IfTrue the points are drawn with thebadcolormap color (seeColormap.set_bad).

Returns:
PathCollection
Other Parameters:
dataindexable object, optional

If given, the following parameters also accept a strings, which isinterpreted asdata[s] ifs is a key indata:

x,y,s,linewidths,edgecolors,c,facecolor,facecolors,color

**kwargsPathCollection properties

Property

Description

agg_filter

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

alpha

array-like or float or None

animated

bool

antialiased oraa orantialiaseds

bool or list of bools

array

array-like or None

capstyle

CapStyle or {'butt', 'projecting', 'round'}

clim

(vmin: float, vmax: float)

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

cmap

Colormap or str or None

color

color or list of RGBA tuples

edgecolor orec oredgecolors

color or list ofcolor or 'face'

facecolor orfacecolors orfc

color or list ofcolor

figure

Figure orSubFigure

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

unknown

hatchcolor

color or list ofcolor or 'edge'

in_layout

bool

joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

label

object

linestyle ordashes orlinestyles orls

str or tuple or list thereof

linewidth orlinewidths orlw

float or list of floats

mouseover

bool

norm

Normalize or str or None

offset_transform ortransOffset

Transform

offsets

(N, 2) or (2,) array-like

path_effects

list ofAbstractPathEffect

paths

unknown

picker

None or bool or float or callable

pickradius

float

rasterized

bool

sizes

numpy.ndarray or None

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

urls

list of str or None

visible

bool

zorder

float

See also

plot

To plot scatter plots when markers are identical in size and color.

Notes

  • Theplot 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.

Examples usingmatplotlib.pyplot.scatter#

Scatter plot with masked values

Scatter plot with masked values

Scatter plot with a legend

Scatter plot with a legend

Hyperlinks

Hyperlinks

Scatter plot on polar axis

Scatter plot on polar axis

Hatchcolor Demo

Hatchcolor Demo

Scatter plot

Scatter plot

Pyplot tutorial

Pyplot tutorial