matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (2024)

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, plotnonfinite=False, data=None, **kwargs)[source]#

A scatter plot of y 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 set linewidth=0 oredgecolor='none'.

carray-like or list of color or color, optional

The marker colors. Possible values:

  • A scalar or sequence of n numbers to be mapped to colors usingcmap and norm.

  • A 2D array in which the rows are RGB or RGBA.

  • A sequence of colors of length n.

  • A single color format string.

Note that c 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 and y.

If you wish to specify a single color for all pointsprefer the color keyword argument.

Defaults to None. In that case the marker color is determinedby the value of color, facecolor or facecolors. In casethose are not specified or None, the marker color is determinedby the next color of the Axes' current "shape and fill" colorcycle. This cycle defaults to rcParams["axes.prop_cycle"] (default: cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])).

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.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 if c is RGB(A).

normstr or Normalize, optional

The normalization method used to scale scalar data to the [0, 1] rangebefore mapping to colors using cmap. 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(see Colormap 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 suitable Normalize subclass is dynamically generatedand instantiated.

This parameter is ignored if c is RGB(A).

vmin, vmaxfloat, optional

When using scalar data and no explicit norm, vmin and vmax 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 a norm instance is given (but using a str normname together with vmin/vmax is acceptable).

This parameter is ignored if c 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 default edgecolorsis 'face'. You may want to change this as well.

edgecolors{'face', 'none', None} or color or list of color, 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. from c, colors, orfacecolors.

plotnonfinitebool, default: False

Whether to plot points with nonfinite c (i.e. inf, -infor nan). If True the points are drawn with the badcolormap color (see Colormap.set_bad).

Returns:
PathCollection
Other Parameters:
dataindexable object, optional

If given, the following parameters also accept a string s, which isinterpreted as data[s] (unless this raises an exception):

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

**kwargsCollection properties

See also

plot

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

Notes

Note

This is the pyplot wrapper for axes.Axes.scatter.

  • The plot function will be faster for scatterplots where markersdon't vary in size or color.

  • Any or all of x, y, s, and c 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, and cmay be input as N-D arrays, but within scatter they will beflattened. The exception is c, which will be flattened only if itssize matches the size of x and y.

Examples using matplotlib.pyplot.scatter#

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (1)

Scatter Masked

Scatter Masked

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (2)

Scatter plots with a legend

Scatter plots with a legend

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (3)

Scatter plot on polar axis

Scatter plot on polar axis

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (4)

Scatter plot

Scatter plot

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (5)

Hyperlinks

Hyperlinks

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (6)

Pyplot tutorial

Pyplot tutorial

matplotlib.pyplot.scatter — Matplotlib 3.9.1 documentation (2024)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6219

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.