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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | NumericArray | Yes | — | X coordinates or table variable selector. |
y | NumericArray | Yes | — | Y coordinates or table variable selector. |
nbins | NumericArray | No | — | Scalar or two-element bin count. |
nameValuePairs | Any | Variadic | — | Binscatter name-value options. |
tbl | Any | Yes | — | Input table or timetable. |
ax | AxesHandle | Yes | — | Target axes handle. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the Binscatter chart. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:binscatter:InvalidArgument | Inputs, bin controls, or chart options are malformed. | binscatter: invalid argument |
RunMat:binscatter:Internal | RunMat 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 2Use 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.
Related functions
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.