Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

Scatter in MATLAB: scatter, scatter3 and gscatter

How to make a scatter plot in MATLAB with scatter, scatter3 and gscatter: marker size, color, filled markers, grouping and troubleshooting.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: in MATLAB, scatter(x,y) draws one marker per (x, y) pair. Add a third argument for marker size, a fourth for color, and use gscatter (Statistics and Machine Learning Toolbox) when you want one marker style per group. This guide is for researchers and analysts who have two numeric variables and need a labelled scatter plot they can read and edit.

What scatter plots in MATLAB are used for in research

A scatter plot shows the relationship between two numeric variables, one marker per observation. Researchers use it to inspect a trend, spot outliers before fitting a model, and compare groups. MATLAB offers several functions for this; the table is the quickest way to pick one. Every row comes from the MathWorks documentation listed under Sources.

Function Use it when Key arguments Where documented
scatter Two variables, optional per-marker size and color scatter(x,y,sz,c), "filled", a marker symbol, or scatter(tbl,xvar,yvar) for table data MATLAB
scatter3 Three variables in 3-D scatter3(X,Y,Z,S,C), or scatter3(tbl,xvar,yvar,zvar) MATLAB
gscatter Color or symbol by group gscatter(x,y,g,clr,sym,siz) Statistics and Machine Learning Toolbox
plot Related function listed on the scatter reference page see the plot reference page MATLAB

gscatter is documented with the Statistics and Machine Learning Toolbox and does not appear in the See also list of the scatter reference page, which is why searchers often miss it.

Install or access MATLAB (official source only)

scatter and scatter3 are documented in the core MATLAB reference at mathworks.com/help/matlab. gscatter is documented under mathworks.com/help/stats, which is the Statistics and Machine Learning Toolbox. Obtain MATLAB and its toolboxes from MathWorks directly or through your institution’s licence, and check the toolbox list in your installation before using gscatter.

How to make a scatter plot in MATLAB (step by step)

This is also the answer to “how to see a scatter plot”: the figure window opens when the command runs.

  1. Put your data in two vectors of equal length, for example x and y, or in a table with named variables.
  2. Run scatter(x,y). Each (x, y) pair is drawn with the default marker, a circle ("o").
  3. For table data, run scatter(tbl,xvar,yvar), where xvar and yvar name the table variables.
  4. To plot into a specific axes, pass it first: scatter(ax,x,y).
  5. To change the plot after creation, capture the result: s = scatter(x,y). The output is a Scatter object (or an array of them) whose properties you can set.

Scatter in MATLAB: marker size, color and filled markers

The third argument sz is the area of each marker in points squared. The default is 36, and an empty array [] selects it. A scalar sizes every marker the same; a vector or matrix sizes each marker individually. Because sz is an area, doubling a marker’s diameter means multiplying sz by 4 (area scales with the square of the diameter).

The fourth argument c sets color. It can be a color name, an RGB triplet, an n-by-3 RGB matrix, or a vector of colormap indices. With indices, the smallest value maps to the first row of the colormap and the largest to the last row; this form requires x, y and sz all to be vectors. For colormap choices see MATLAB colormap colors and MATLAB plot color.

Add "filled" to fill the markers: scatter(x,y,sz,c,"filled"). This sets MarkerFaceColor to "flat" and MarkerEdgeColor to "none". Marker symbols without faces (+, *, ., x, _, |) do not appear when "filled" is used. Other symbols include square, diamond, ^, v, >, <, pentagram and hexagram. For per-point transparency, use AlphaData with MarkerFaceAlpha set to "flat".

Matlab scatter by group with gscatter

gscatter(x,y,g) plots x against y and gives all points in the same group the same marker color, symbol and size. The grouping variable g may be categorical, logical, numeric, a character array, a string array or a cell array of character vectors, and the number of rows in g must equal the length of x. To group by several variables, pass them as {g1 g2}. The full form is gscatter(x,y,g,clr,sym,siz); pass [] to accept a default. The default symbol is ., and the legend is on by default (doleg is 'on'). With h = gscatter(___) you get an array of Line objects, one per group.

3-D scatter with scatter3

scatter3(X,Y,Z) plots three variables; scatter3(X,Y,Z,S,C) adds size and color in the same way as scatter, and the table form is scatter3(tbl,xvar,yvar,zvar). It also accepts "filled", a marker type, an axes first argument and Name=Value options.

Output and how to read it

Each marker is one observation. A rising or falling cloud suggests a monotone relationship; a shapeless cloud suggests none; isolated markers away from the cloud are candidates for checking as outliers or entry errors. Colored or sized markers add a third variable, so state in the figure caption what color and size encode. For a full treatment of reading patterns, see scatterplot interpretation. A scatter plot in school mathematics (for example 8th grade) is the same object: points plotted on x and y axes to show whether two variables are related.

Troubleshooting

  • Color by value fails or ignores colors: the colormap-index form of c only works when x, y and sz are all vectors.
  • Markers disappeared after adding “filled”: +, *, ., x, _ and | have no face, so they are not drawn when "filled" is set. Use a face-bearing symbol such as "o".
  • gscatter errors on size mismatch: the rows of g must equal the length of x.
  • Markers are too small or large: sz is an area in points squared; the default is 36.
  • Need to edit after plotting: store the output, s = scatter(___), and set properties on s.

Other tools for the same plot

Tool Guide on this site
R Scatterplots in R
Python Scatter plot in Python
Stata Scatterplots in Stata with twoway scatter
SPSS Scatterplots in SPSS Chart Builder

For help deciding between MATLAB and R, see MATLAB vs R; for what MATLAB is used for generally, see what MATLAB is used for.

FAQ

How to make a scatter plot in MATLAB?

Create two equal-length vectors and run scatter(x,y). Add sz for marker area and c for color as the third and fourth arguments.

How to see a scatter plot?

Running scatter opens the figure window showing the plot; keep the output s = scatter(x,y) if you want to adjust it afterwards.

How to do a scatter plot on Stata?

Stata uses twoway scatter; the steps are in Scatterplots in Stata with twoway scatter.

What is a scatter plot in 8th grade?

Points plotted on a coordinate grid to show whether two variables are related, the same idea used in research.

Sources (read 2026-11-07)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Scatter in MATLAB: scatter, scatter3 and gscatter

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →