Scatter plot - MATLAB scatter (2024)

Table of Contents
Syntax Description Vector and Matrix Data Table Data Additional Options Examples Create Scatter Plot Vary Circle Size Vary Circle Color Vary Color Palette Fill the Markers Specify Marker Symbol Change Marker Color and Line Width Vary Transparency Across Data Points Plot Data from a Table Plot Table Data with Custom Colors and Marker Sizes Specify Target Axes and Marker Type Modify Scatter Series After Creation Input Arguments x — x-coordinates scalar | vector | matrix y — y-coordinates scalar | vector | matrix sz — Marker size 36 (default) | numeric scalar | row or column vector | matrix | [] c — Marker color color name | RGB triplet | matrix of RGB triplets | vector of colormap indices mkr — Marker symbol "o" (default) | "+" | "*" | "." | "x" | ... "filled" — Option to fill interior of markers "filled" tbl — Source table table | timetable xvar — Table variables containing x-coordinatesone or more table variable indices yvar — Table variables containing y-coordinates one or more table variable indices ax — Target axes Axes object | PolarAxes object | GeographicAxes object Name-Value Arguments ColorVariable — Table variable containing color data table variable index Output Arguments s — Scatter object Scatter object | array of Scatter objects Extended Capabilities Tall Arrays Calculate with arrays that have more rows than fit in memory. GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™. Distributed ArraysPartition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™. Version History R2022b: Plots created with tables preserve special characters in axis and legend labels R2021b: Pass tables directly to scatter See Also Functions Properties Topics External Websites MATLAB Command Americas Europe Asia Pacific FAQs

Scatter plot

collapse all in page

  • Scatter plot - MATLAB scatter (1)

Syntax

scatter(x,y)

scatter(x,y,sz)

scatter(x,y,sz,c)

scatter(___,"filled")

scatter(___,mkr)

scatter(tbl,xvar,yvar)

scatter(tbl,xvar,yvar,"filled")

scatter(ax,___)

scatter(___,Name,Value)

s = scatter(___)

Description

Vector and Matrix Data

example

scatter(x,y) creates a scatter plot with circular markers at the locations specified by the vectors x and y.

  • To plot one set of coordinates, specify x and y as vectors of equal length.

  • To plot multiple sets of coordinates on the same set of axes, specify at least one of x or y as a matrix.

example

scatter(x,y,sz) specifies the circle sizes. To use the same size for all the circles, specify sz as a scalar. To plot each circle with a different size, specify sz as a vector or a matrix.

example

scatter(x,y,sz,c) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red".

example

scatter(___,"filled") fills in the circles. Use the "filled" option with any of the input argument combinations in the previous syntaxes.

example

scatter(___,mkr) specifiesthe marker type.

Table Data

example

scatter(tbl,xvar,yvar) plots the variables xvar and yvar from the table tbl. To plot one data set, specify one variable for xvar and one variable for yvar. To plot multiple data sets, specify multiple variables for xvar, yvar, or both. If both arguments specify multiple variables, they must specify the same number of variables. (Since R2021b)

example

scatter(tbl,xvar,yvar,"filled") plots the specified variables from the table with filled circles. (Since R2021b)

Additional Options

example

scatter(ax,___) plots into the axes specified by ax instead of into the current axes. The option ax can precede any of the input argument combinations in the previous syntaxes.

example

scatter(___,Name,Value) modifies the scatter plot using one or more name-value arguments to set properties. For example:

  • scatter(x,y,"LineWidth",2) creates a scatter plot with 2-point marker outlines.

  • scatter(tbl,"MyX","MyY","ColorVariable","MyColors") creates a scatter plot from data in a table, and customizes the marker colors using data from the table.

For a full list of properties, see Scatter Properties.

example

s = scatter(___) returns the Scatter object or an array of Scatter objects. Use s to set properties after creating the plot. For a full list of properties, see Scatter Properties.

Examples

collapse all

Create Scatter Plot

Open Live Script

Create x as 200 equally spaced values between 0 and 3π. Create y as cosine values with random noise. Then, create a scatter plot.

x = linspace(0,3*pi,200);y = cos(x) + rand(1,200); scatter(x,y)

Scatter plot - MATLAB scatter (2)

Vary Circle Size

Open Live Script

Create a scatter plot using circles with different sizes. Specify the size in points squared

x = linspace(0,3*pi,200);y = cos(x) + rand(1,200);sz = linspace(1,100,200);scatter(x,y,sz)

Scatter plot - MATLAB scatter (3)

Corresponding elements in x, y, and sz determine the location and size of each circle. To plot all circles with the equal area, specify sz as a numeric scalar.

Vary Circle Color

Open Live Script

Create a scatter plot and vary the circle color.

x = linspace(0,3*pi,200);y = cos(x) + rand(1,200);c = linspace(1,10,length(x));scatter(x,y,[],c)

Scatter plot - MATLAB scatter (4)

Corresponding elements in x, y, and c determine the location and color of each circle. The scatter function maps the elements in c to colors in the current colormap.

Vary Color Palette

Since R2023b

Named color palettes provide a convenient way to change the colors of a chart. This example compares a scatter plot with three different color palettes.

Create a scatter plot of random numbers using the default palette.

x = rand(50,5);y = randn(50,5) + (5:5:25);scatter(x,y,"filled")

Scatter plot - MATLAB scatter (5)

Change the color palette to reef by using colororder function.

colororder("reef")

Scatter plot - MATLAB scatter (6)

Change the color palette to meadow.

colororder("meadow")

Scatter plot - MATLAB scatter (7)

Fill the Markers

Open Live Script

Create a scatter plot and fill in the markers. scatter fills each marker using the color of the marker edge.

x = linspace(0,3*pi,200);y = cos(x) + rand(1,200);sz = 25;c = linspace(1,10,length(x));scatter(x,y,sz,c,'filled')

Scatter plot - MATLAB scatter (8)

Specify Marker Symbol

Open Live Script

Create vectors x and y as sine and cosine values with random noise. Then, create a scatter plot and use diamond markers with an area of 140 points squared.

theta = linspace(0,2*pi,150);x = sin(theta) + 0.75*rand(1,150);y = cos(theta) + 0.75*rand(1,150); sz = 140;scatter(x,y,sz,'d')

Scatter plot - MATLAB scatter (9)

Change Marker Color and Line Width

Open Live Script

Create vectors x and y as sine and cosine values with random noise. Create a scatter plot and set the marker edge color, marker face color, and line width.

theta = linspace(0,2*pi,300);x = sin(theta) + 0.75*rand(1,300);y = cos(theta) + 0.75*rand(1,300); sz = 40;scatter(x,y,sz,'MarkerEdgeColor',[0 .5 .5],... 'MarkerFaceColor',[0 .7 .7],... 'LineWidth',1.5)

Scatter plot - MATLAB scatter (10)

Vary Transparency Across Data Points

Open Live Script

You can vary the transparency of scattered points by setting the AlphaData property to a vector of different opacity values. To ensure the scatter plot uses the AlphaData values, set the MarkerFaceAlpha property to 'flat'.

Create a set of normally distributed random numbers. Then create a scatter plot of the data with filled markers.

x = randn(1000,1);y = randn(1000,1);s = scatter(x,y,'filled');

Scatter plot - MATLAB scatter (11)

Set the opacity of each point according to its distance from zero.

distfromzero = sqrt(x.^2 + y.^2);s.AlphaData = distfromzero;s.MarkerFaceAlpha = 'flat';

Scatter plot - MATLAB scatter (12)

Plot Data from a Table

Open Live Script

Since R2021b

A convenient way to plot data from a table is to pass the table to the scatter function and specify the variables you want to plot. For example, read patients.xls as a table tbl. Plot the relationship between the Systolic and Diastolic variables by passing tbl as the first argument to the scatter function followed by the variable names. Notice that the axis labels match the variable names.

tbl = readtable('patients.xls');scatter(tbl,'Systolic','Diastolic');

Scatter plot - MATLAB scatter (13)

You can also plot multiple variables at the same time. For example, plot both blood pressure variables versus the Weight variable by specifying the yvar argument as the cell array {'Systolic','Diastolic'}. Add a legend, and notice that the legend labels match the variable names.

scatter(tbl,'Weight',{'Systolic','Diastolic'});legend

Scatter plot - MATLAB scatter (14)

Plot Table Data with Custom Colors and Marker Sizes

Open Live Script

Since R2021b

One way to plot data from a table and customize the colors and marker sizes is to set the ColorVariable and SizeData properties. You can set these properties as name-value arguments when you call the scatter function, or you can set them on the Scatter object later.

For example, read patients.xls as a table tbl. Plot the Height variable versus the Weight variable with filled markers. Vary the marker colors by specifying the ColorVariable name-value argument. Return the Scatter object as s, so you can set other properties later.

tbl = readtable('patients.xls');s = scatter(tbl,'Weight','Height','filled','ColorVariable','Diastolic');

Scatter plot - MATLAB scatter (15)

Change the marker sizes to 100 points by setting the SizeData property. Then add a colorbar.

s.SizeData = 100;colorbar

Scatter plot - MATLAB scatter (16)

Specify Target Axes and Marker Type

Open Live Script

Since R2019b

You can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Plot scattered data into each axes. In the bottom scatter plot, specify diamond filled diamond markers.

x = linspace(0,3*pi,200);y = cos(x) + rand(1,200);tiledlayout(2,1)% Top plotax1 = nexttile;scatter(ax1,x,y)% Bottom plotax2 = nexttile;scatter(ax2,x,y,'filled','d')

Scatter plot - MATLAB scatter (17)

Modify Scatter Series After Creation

Open Live Script

Create a scatter plot and return the scatter series object, s.

theta = linspace(0,1,500);x = exp(theta).*sin(100*theta);y = exp(theta).*cos(100*theta);s = scatter(x,y);

Scatter plot - MATLAB scatter (18)

Use s to query and set properties of the scatter series after it has been created. Set the line width to 0.6 point. Set the marker edge color to blue. Set the marker face color using an RGB triplet color.

s.LineWidth = 0.6;s.MarkerEdgeColor = 'b';s.MarkerFaceColor = [0 0.5 0.5];

Scatter plot - MATLAB scatter (19)

Input Arguments

collapse all

xx-coordinates
scalar | vector | matrix

x-coordinates, specified as a scalar, vector, or matrix. The size and shape of x depends on the shape of your data. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify x and y as scalars. For example:

scatter(1,2)
One set of points

Specify x and y as any combination of row or column vectors of the same length. For example:

scatter([1 2 3],[4; 5; 6])
Multiple sets of points that are different colors

If all the sets share the same x- or y-coordinates, specify the shared coordinates as a vector and the other coordinates as a matrix. The length of the vector must match one of the dimensions of the matrix. For example:

scatter([1 2 3],[4 5 6; 7 8 9])
If the matrix is square, scatter plots a separate set of points for each column in the matrix.

Alternatively, specify x and y as matrices of equal size. In this case, scatter plots each column of y against the corresponding column of x. For example:

scatter([1 3 5; 2 4 6],[10 25 45; 20 40 60])

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

yy-coordinates
scalar | vector | matrix

y-coordinates, specified as a scalar, vector, or matrix. The size and shape of y depends on the shape of your data. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify x and y as scalars. For example:

scatter(1,2)
One set of points

Specify x and y as any combination of row or column vectors of the same length. For example:

scatter([1 2 3],[4; 5; 6])
Multiple sets of points that are different colors

If all the sets share the same x- or y-coordinates, specify the shared coordinates as a vector and the other coordinates as a matrix. The length of the vector must match one of the dimensions of the matrix. For example:

scatter([1 2 3],[4 5 6; 7 8 9])
If the matrix is square, scatter plots a separate set of points for each column in the matrix.

Alternatively, specify x and y as matrices of equal size. In this case, scatter plots each column of y against the corresponding column of x. For example:

scatter([1 3 5; 2 4 6],[10 25 45; 20 40 60])

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

szMarker size
36 (default) | numeric scalar | row or column vector | matrix | []

Marker size, specified as a numeric scalar, vector, matrix, or empty array ([]). The size controls the area of each marker in points squared. An empty array specifies the default size of 36 points. The way you specify the size depends on how you specify x and y, and how you want the plot to look. This table describes the most common situations.

Desired Marker Sizesx and y szExample

Same size for all points

Any valid combination of vectors or matrices described for x and y.

Scalar

Specify x as a vector, y as a matrix, and sz as a scalar.

x = [1 2 3 4];y = [1 6; 3 8; 2 7; 4 9];scatter(x,y,100)

Different size for each point

Vectors of the same length

  • A vector with the same length as x and y.

  • A matrix with at least one dimension that matches the lengths of x and y. Specifying a matrix is useful for displaying multiple markers with different sizes at each (x,y) location.

Specify x, y, and sz as vectors.

x = [1 2 3 4];y = [1 3 2 4];sz = [80 150 700 50];scatter(x,y,sz)

Specify x and y as vectors and sz as a matrix.

x = [1 2 3 4];y = [1 3 2 4];sz = [80 30; 150 900; 50 2000; 200 350];scatter(x,y,sz)

Different size for each point

At least one of x or y is a matrix for plotting multiple data sets

  • A vector with the same number of elements as there are points in each data set.

  • A matrix that has the same size as the x or y matrix.

Specify x as a vector, y as a matrix, and sz as vector.

x = [1 2 3 4];y = [1 6; 3 8; 2 7; 4 9];sz = [80 150 50 700];scatter(x,y,sz)

Specify x as a vector, y as a matrix, and sz as a matrix the same size as y.

x = [1 2 3 4];y = [1 6; 3 8; 2 7; 4 9];sz = [80 30; 150 900; 50 2000; 200 350];scatter(x,y,sz)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

cMarker color
color name | RGB triplet | matrix of RGB triplets | vector of colormap indices

Marker color, specified as a color name, RGB triplet, matrix of RGB triplets, or a vector of colormap indices.

  • Color name — A color name such as "red", or a short name such as "r".

  • RGB triplet — A three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. RGB triplets are useful for creating custom colors.

  • Matrix of RGB triplets — A three-column matrix in which each row is an RGB triplet.

  • Vector of colormap indices — A vector of numeric values that is the same length as the x and y vectors.

The way you specify the color depends on the desired color scheme and whether you are plotting one set of coordinates or multiple sets of coordinates. This table describes the most common situations.

Color SchemeHow to Specify the ColorExample

Use one color for all the points.

Specify a color name or a short name from the table below, or specify one RGB triplet.

Plot one set of points, and specify the color as "red".

scatter(1:4,[2 5 3 7],[],"red")

Plot two sets of points, and specify the color as red using an RGB triplet.

scatter(1:4,[2 5; 1 2; 8 4; 11 9],[],[1 0 0])

Assign different colors to each point using a colormap.

Specify a row or column vector of numbers. The numbers map into the current colormap array. The smallest value maps to the first row in the colormap, and the largest value maps to the last row. The intermediate values map linearly to the intermediate rows.

If your plot has three points, specify a column vector to ensure the values are interpreted as colormap indices.

You can use this method only when x, y, and sz are all vectors.

Create a vector c that specifies four colormap indices. Plot four points using the colors from the current colormap. Then, change the colormap to winter.

c = 1:4;scatter(1:4,[2 5 3 7],[],c)colormap(gca,"winter")

Create a custom color for each point.

Specify an m-by-3 matrix of RGB triplets, where m is the number of points in the plot.

You can use this method only when x, y, and sz are all vectors.

Create a matrix c that specifies RGB triplets for green, red, gray, and purple. Then create a scatter plot of four points using those colors.

c = [0 1 0; 1 0 0; 0.5 0.5 0.5; 0.6 0 1];scatter(1:4,[2 5 3 7],[],c)

Create a different color for each data set.

Specify an n-by-3 matrix of RGB triplets, where n is the number of data sets.

You can use this method only when at least one of x, y, or sz is a matrix.

Create a matrix c that contains two RGB triplets. Then plot two data sets using those colors.

c = [1 0 0; 0.6 0 1];s = scatter(1:4,[2 5; 1 2; 8 4; 11 9],[],c)

Color Names and RGB Triplets for Common Colors

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Scatter plot - MATLAB scatter (20)

"green""g"[0 1 0]"#00FF00"

Scatter plot - MATLAB scatter (21)

"blue""b"[0 0 1]"#0000FF"

Scatter plot - MATLAB scatter (22)

"cyan" "c"[0 1 1]"#00FFFF"

Scatter plot - MATLAB scatter (23)

"magenta""m"[1 0 1]"#FF00FF"

Scatter plot - MATLAB scatter (24)

"yellow""y"[1 1 0]"#FFFF00"

Scatter plot - MATLAB scatter (25)

"black""k"[0 0 0]"#000000"

Scatter plot - MATLAB scatter (26)

"white""w"[1 1 1]"#FFFFFF"

Scatter plot - MATLAB scatter (27)

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Scatter plot - MATLAB scatter (28)

[0.8500 0.3250 0.0980]"#D95319"

Scatter plot - MATLAB scatter (29)

[0.9290 0.6940 0.1250]"#EDB120"

Scatter plot - MATLAB scatter (30)

[0.4940 0.1840 0.5560]"#7E2F8E"

Scatter plot - MATLAB scatter (31)

[0.4660 0.6740 0.1880]"#77AC30"

Scatter plot - MATLAB scatter (32)

[0.3010 0.7450 0.9330]"#4DBEEE"

Scatter plot - MATLAB scatter (33)

[0.6350 0.0780 0.1840]"#A2142F"

Scatter plot - MATLAB scatter (34)

mkrMarker symbol
"o" (default) | "+" | "*" | "." | "x" | ...

Marker symbol, specified as one of the values listed in this table.

MarkerDescriptionResulting Marker
"o"Circle

Scatter plot - MATLAB scatter (35)

"+"Plus sign

Scatter plot - MATLAB scatter (36)

"*"Asterisk

Scatter plot - MATLAB scatter (37)

"."Point

Scatter plot - MATLAB scatter (38)

"x"Cross

Scatter plot - MATLAB scatter (39)

"_"Horizontal line

Scatter plot - MATLAB scatter (40)

"|"Vertical line

Scatter plot - MATLAB scatter (41)

"square"Square

Scatter plot - MATLAB scatter (42)

"diamond"Diamond

Scatter plot - MATLAB scatter (43)

"^"Upward-pointing triangle

Scatter plot - MATLAB scatter (44)

"v"Downward-pointing triangle

Scatter plot - MATLAB scatter (45)

">"Right-pointing triangle

Scatter plot - MATLAB scatter (46)

"<"Left-pointing triangle

Scatter plot - MATLAB scatter (47)

"pentagram"Pentagram

Scatter plot - MATLAB scatter (48)

"hexagram"Hexagram

Scatter plot - MATLAB scatter (49)

"filled"Option to fill interior of markers
"filled"

Option to fill the interior of the markers, specified as "filled". Use this option with markers that have a face, for example, "o" or "square". Markers that do not have a face and contain only edges do not draw ("+", "*", ".", and "x").

The "filled" option sets the MarkerFaceColor property of the Scatter object to "flat" and the MarkerEdgeColor property to "none", so the marker faces draw, but the edges do not.

tblSource table
table | timetable

Source table containing the data to plot, specified as a table or a timetable.

xvarTable variables containing x-coordinates
one or more table variable indices

Table variables containing the x-coordinates, specified as one or more table variable indices.

Specifying Table Indices

Use any of the following indexing schemes to specify the desired variable or variables.

Indexing SchemeExamples

Variable names:

  • A string, character vector, or cell array.

  • A pattern object.

  • "A" or 'A' — A variable named A

  • ["A","B"] or {'A','B'} — Two variables named A and B

  • "Var"+digitsPattern(1) — Variables named "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A vector of numbers.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

Plotting Your Data

The table variables you specify can contain numeric, categorical, datetime, or duration values.

To plot one data set, specify one variable for xvar, and one variable for yvar. For example, read Patients.xls into the table tbl. Plot the Diastolic variable versus the Weight variable.

tbl = readtable("Patients.xls");scatter(tbl,"Weight","Diastolic")

To plot multiple data sets together, specify multiple variables for xvar, yvar, or both. If you specify multiple variables for both arguments, the number of variables must be the same.

For example, plot the Systolic and Diastolic variables against the Weight variable.

scatter(tbl,"Weight",["Systolic","Diastolic"])

You can use different indexing schemes for xvar and yvar. For example, specify xvar as a variable name and yvar as an index number.

scatter(tbl,"Weight",9)

yvarTable variables containing y-coordinates
one or more table variable indices

Table variables containing the y-coordinates, specified as one or more table variable indices.

Specifying Table Indices

Use any of the following indexing schemes to specify the desired variable or variables.

Indexing SchemeExamples

Variable names:

  • A string, character vector, or cell array.

  • A pattern object.

  • "A" or 'A' — A variable named A

  • ["A","B"] or {'A','B'} — Two variables named A and B

  • "Var"+digitsPattern(1) — Variables named "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A vector of numbers.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

Plotting Your Data

The table variables you specify can contain numeric, categorical, datetime, or duration values.

To plot one data set, specify one variable for xvar, and one variable for yvar. For example, read Patients.xls into the table tbl. Plot the Diastolic variable versus the Weight variable.

tbl = readtable("Patients.xls");scatter(tbl,"Weight","Diastolic")

To plot multiple data sets together, specify multiple variables for xvar, yvar, or both. If you specify multiple variables for both arguments, the number of variables must be the same.

For example, plot the Systolic and Diastolic variables against the Weight variable.

scatter(tbl,"Weight",["Systolic","Diastolic"])

You can use different indexing schemes for xvar and yvar. For example, specify xvar as a variable name and yvar as an index number.

scatter(tbl,"Weight",9)

axTarget axes
Axes object | PolarAxes object | GeographicAxes object

Target axes, specified as an Axes object, a PolarAxes object, or a GeographicAxes object. If you do not specify the axes and the current axes object is Cartesian, then the scatter function plots into the current axes.

A convenient way to create scatter plots in polar or geographic coordinates is to use the polarscatter or geoscatter functions.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "MarkerFaceColor","red" sets the marker face color to red.

The Scatter object properties listed here areonly a subset. For a complete list, see Scatter Properties.

ColorVariableTable variable containing color data
table variable index

Table variable containing the color data, specified as a variable index into the source table.

Specifying the Table Index

Use any of the following indexing schemes to specify the desired variable.

Indexing SchemeExamples

Variable name:

  • A string scalar or character vector.

  • A pattern object. The pattern object must refer to only one variable.

  • "A" or 'A' — A variable named A

  • "Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable.

  • vartype("double") — The variable containing double values

Specifying Color Data

Specifying the ColorVariable property controls the colors of the markers. The data in the variable controls the marker fill color when the MarkerFaceColor property is set to "flat". The data can also control the marker outline color, when the MarkerEdgeColor is set to "flat".

The table variable you specify can contain values of any numeric type. The values can be in either of the following forms:

  • A column of numbers that linearly map into the current colormap.

  • A three-column array of RGB triplets. RGB triplets are three-element vectors whose values specify the intensities of the red, green, and blue components of specific colors. The intensities must be in the range [0,1]. For example, [0.5 0.7 1] specifies a shade of light blue.

When you set the ColorVariable property, MATLAB updates the CData property.

Output Arguments

collapse all

sScatter object
Scatter object | array of Scatter objects

Scatter object or an array of Scatter objects. Use s to modify properties of a scatter chart after creating it.

Extended Capabilities

Version History

Introduced before R2006a

expand all

Create plots by passing a table to the scatter function followed by the variables you want to plot. When you specify your data as a table, the axis labels and the legend (if present) are automatically labeled using the table variable names.

See Also

Functions

  • hold | plot | scatter3 | bubblechart | swarmchart

Properties

  • Scatter Properties

Topics

  • Plot Dates and Times
  • Plot Categorical Data
  • Plots That Support Tables

External Websites

  • MATLAB PlotGallery

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Scatter plot - MATLAB scatter (52)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Scatter plot - MATLAB scatter (2024)

FAQs

How do you make a scatter plot look better? ›

Making an excellent scatter plot

Strive for clarity: Each point on a scatter plot represents one data point. You'll want to make sure that these points are big enough to see, but not so big they obscure each other. Unless you have a very good reason to add color, it is probably best to keep a scatter plot grayscale.

What is a scatterplot and how does it help us? ›

A scatter plot identifies a possible relationship between changes observed in two different sets of variables. It provides a visual and statistical means to test the strength of a relationship between two variables.

How to make a trend line in MATLAB? ›

Alright, after a lot of research and too much time wasted, you can find the trend line of a linear graph through this equation: “=LINEST([y-values],[x-values],[constant])”. Linest is just the same as slope and constant serves as a fixed y-intercept. Be sure that you didn't switch your x and y values though!

How do you know if a scatter plot is a good fit? ›

To determine the best-fit line for a scatter plot, one commonly used method is linear regression. This involves finding the line that minimizes the sum of the squared vertical distances (residuals) between each data point and the line.

What does a strong scatter plot look like? ›

If the points are clearly clustered, or closely follow a curve or line, the relationship is described as strong. The linearity of scatter plot indicates how close the points are to a straight line.

How do you color scatter in MATLAB? ›

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red" .

How to make a graph pink in MATLAB? ›

RGB Triplet — Create a custom color by specifying a three-element row vector whose elements are the intensities of the red, green, and blue components of a color. The intensities must be in the range [0,1] . For example, you can specify a shade of pink as [1 0.5 0.8] .

What is the code for purple in MATLAB? ›

purple = [107 76 154]./255; cl_colors = {blue, red, black, ...

How to analyze a scatter plot? ›

First, to read a scatter plot, make sure you understand what the independent (x-axis) and dependent variables (y-axis) are measuring. Next, we examine the view to see if we can identify a correlation between fields in the view. If the variables correlate they will fall along a line or curve.

What is an alternative to a scatter plot? ›

Heatmap. As noted above, a heatmap can be a good alternative to the scatter plot when there are a lot of data points that need to be plotted and their density causes overplotting issues.

What conclusions can be made from a scatter plot? ›

Scatterplots can visually show the strength of the relationship between the variables (i.e., the “scatter” in the plot: the more concentrated the dots are along the line, the stronger the relationship); whether there is a positive or negative association between the variables (i.e., whether the slope is positive or ...

How do you make a pretty graph in MATLAB? ›

you'll want to use the 'Color' option in your plot statement. Right after color, include a vector with the RGB color values of whatever color you want. For example plot(x,y,'Color',1/255*[148 0 211]) will produce a very nice shade of purple. You can easily find RGB color codes for various colors online.

How to draw the best fit curve in MATLAB? ›

Curve Fitting
  1. Load some data at the MATLAB® command line. ...
  2. Open the Curve Fitter app. ...
  3. In the Curve Fitter app, on the Curve Fitter tab, in the Data section, click Select Data. ...
  4. Choose a different model type from the fit gallery in the Fit Type section of the Curve Fitter tab.

How do you plot a line with dots in MATLAB? ›

Add Markers to Line Plot

Create a line plot. Display a marker at each data point by including the line-specification input argument when calling the plot function. For example, use '-o' for a solid line with circle markers.

How can a scatter plot be improved? ›

One way is to very slightly nudge each data point away from the cluster center by manually moving the point. Another way is to make the fill colour of each point slightly transparent and change the border colour of all data points in the scatterplot so they stand out against one another better.

How do you make a graph look good? ›

Make sure data items are evenly spaced and do not overlap with one another. Be as concise as possible – most people can only focus on 2 or 3 data points at a time. Use color to clearly indicate different segments or categories. Graphs in the same presentation should follow the same scheme (color, font, etc.)

How do you make a scatter plot less cluttered? ›

However, be careful not to use too many colors or sizes, as they can make your scatter plot too cluttered or distracting. Choose a color palette that is easy to distinguish and consistent with your data type and message. Use size sparingly and with a clear legend or scale.

What makes a scatter plot positive? ›

A scatterplot with a positive correlation is a graph that shows that all of the data points are in a pattern trending upwards from left to right. The scatterplot shows that, in general, as x increases, y increases as well which means the data points have a positive association or relationship.

Top Articles
Nelson Mandela's daughter: I don't know if my father loves me. Sometimes children are not really loved by their parents
Copycat Kudos Granola Bars - The Squeaky Mixer
Play FETCH GAMES for Free!
Pixel Speedrun Unblocked 76
Kraziithegreat
From Algeria to Uzbekistan-These Are the Top Baby Names Around the World
Kansas Craigslist Free Stuff
Sam's Club Gas Price Hilliard
Merlot Aero Crew Portal
Monticello Culver's Flavor Of The Day
Best Private Elementary Schools In Virginia
LeBron James comes out on fire, scores first 16 points for Cavaliers in Game 2 vs. Pacers
South Bend Tribune Online
Https://Gw.mybeacon.its.state.nc.us/App
今月のSpotify Japanese Hip Hopベスト作品 -2024/08-|K.EG
Uc Santa Cruz Events
Nissan Rogue Tire Size
Caledonia - a simple love song to Scotland
I Saysopensesame
Fsga Golf
All Obituaries | Gateway-Forest Lawn Funeral Home | Lake City FL funeral home and cremation Lake City FL funeral home and cremation
Nsa Panama City Mwr
Gotcha Rva 2022
Engineering Beauties Chapter 1
Nearest Ups Ground Drop Off
Effingham Daily News Police Report
Evil Dead Rise Ending Explained
Yu-Gi-Oh Card Database
Gasbuddy Lenoir Nc
The Venus Flytrap: A Complete Care Guide
Kokomo Mugshots Busted
What Happened To Father Anthony Mary Ewtn
Edward Walk In Clinic Plainfield Il
4083519708
Cross-Border Share Swaps Made Easier Through Amendments to India’s Foreign Exchange Regulations - Transatlantic Law International
Craigs List Stockton
Aliciabibs
450 Miles Away From Me
Skill Boss Guru
Woodman's Carpentersville Gas Price
Pro-Ject’s T2 Super Phono Turntable Is a Super Performer, and It’s a Super Bargain Too
Craigslist Malone New York
Brake Pads - The Best Front and Rear Brake Pads for Cars, Trucks & SUVs | AutoZone
Thotsbook Com
Academic Notice and Subject to Dismissal
Wgu Admissions Login
Joy Taylor Nip Slip
Lira Galore Age, Wikipedia, Height, Husband, Boyfriend, Family, Biography, Net Worth
Sams La Habra Gas Price
View From My Seat Madison Square Garden
Used Curio Cabinets For Sale Near Me
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6678

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.