binscatter — Visualize point density with a two-dimensional binned scatter plot.

binscatter(x,y) bins paired observations and displays the bin counts as a colored tile plot. binscatter(x,y,nbins) accepts a scalar or two-element bin count. binscatter(tbl,xvar,yvar) reads numeric variables from a table or timetable. Name-value options support NumBins, XLimits, YLimits, ShowEmptyBins, FaceAlpha, DisplayName, and DisplayStyle set to "tile".

Syntax

binscatter(x, y)
binscatter(x, y, nbins)
binscatter(___, Name, Value)
binscatter(tbl, xvar, yvar)
binscatter(tbl, xvar, yvar, nbins)
binscatter(ax, ___)
All supported binscatter forms
binscatter(x, y)
binscatter(x, y, nbins)
binscatter(___, Name, Value)
binscatter(tbl, xvar, yvar)
binscatter(tbl, xvar, yvar, nbins)
binscatter(ax, ___)
binscatter(ax, x, y, Name, Value)
h = binscatter(___)
h = binscatter(x, y, nbins)

Inputs

NameTypeRequiredDefaultDescription
xNumericArrayYesX coordinates or table variable selector.
yNumericArrayYesY coordinates or table variable selector.
nbinsNumericArrayNoScalar or two-element bin count.
nameValuePairsAnyVariadicBinscatter name-value options.
tblAnyYesInput table or timetable.
axAxesHandleYesTarget axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the Binscatter chart.

Errors

IdentifierWhenMessage
RunMat:binscatter:InvalidArgumentInputs, bin controls, or chart options are malformed.binscatter: invalid argument
RunMat:binscatter:InternalRunMat cannot compute bins or render the chart.binscatter: internal error

Examples

Create a binned scatter plot

h = binscatter([0; 0.2; 0.8; 1], [0; 0.1; 0.9; 1], [2 2]);
get(h, 'Values')

Expected output:

ans =
     2     0
     0     2

Use explicit limits and show empty bins

h = binscatter(x, y, 'NumBins', [20 10], 'XLimits', [0 1], 'YLimits', [-1 1], 'ShowEmptyBins', 'on');

Expected output:

h is a binscatter chart handle.

Read numeric variables from a table

T = table(x, y);
h = binscatter(T, 'x', 'y', 25);

Expected output:

h is a binscatter chart handle.

Using binscatter with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how binscatter changes the result.

Run a small binscatter example, explain the result, then change one input and compare the output.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.