scatter — Create 2-D scatter plots for point clouds, size/color encoding, and MATLAB scatter workflows.
scatter creates 2-D marker plots from paired x and y coordinates. In RunMat it returns a scatter handle, participates in the shared plotting property system, and supports the MATLAB scatter(x, y, s, c, 'filled') style of workflows for marker size, marker color, and display-name driven chart composition.
How scatter works
scatter(x, y)requires the same element count in both inputs.- The returned value is a scatter-handle object that can be inspected and updated through
getandset. - Marker size, marker face color, marker edge color, and display name all flow through the shared plotting handle model.
- Scatter plots integrate naturally with
subplotandlegend, so series labels and axes-local state stay scoped to the active axes. - GPU-resident point buffers can be rendered directly on the happy path; unsupported combinations fall back to host materialization while preserving the same visible result.
How RunMat runs scatter on the GPU
The direct path keeps point buffers on the device and avoids an unnecessary host round-trip for supported scatter workflows.
Marker styling and legend/display-name behavior stay consistent across GPU and host fallback rendering.
GPU memory and residency
scatter preserves GPU residency when the plotting path can consume exported point buffers directly. If the active marker/style combination cannot use the direct path, RunMat gathers once and renders the same plot semantics on the fallback path.
Examples
Create a basic 2-D scatter plot
t = linspace(0, 2*pi, 100);
scatter(cos(t), sin(t));Use marker sizing and color-style workflows
x = linspace(0, 1, 25);
y = x.^2;
h = scatter(x, y);
set(h, 'SizeData', 12, 'MarkerFaceColor', 'r', 'Marker', 'o');Drive the legend from scatter object display names
x = 1:10;
h1 = scatter(x, x);
set(h1, 'DisplayName', 'linear');
hold on;
h2 = scatter(x, x.^2);
set(h2, 'DisplayName', 'quadratic');
legend;FAQ
How do I color scatter points by a third variable?⌄
Set the CData property on the scatter handle to a vector the same length as x and y. The values map into the current colormap.
x = randn(1, 100);
y = randn(1, 100);
z = x.^2 + y.^2;
h = scatter(x, y);
set(h, 'CData', z);
colorbar;Each point gets a color proportional to its z value. Call colorbar to show the mapping.
What's the difference between scatter and plot?⌄
scatter draws unconnected markers and supports per-point size (SizeData) and per-point color (CData). plot connects points with lines and applies uniform styling to the whole series. Use scatter when the individual point properties carry meaning; use plot when the connection between points is what matters.
How do I control marker size in scatter?⌄
Pass a scalar or vector to SizeData via the handle. A scalar sets uniform size; a vector sets per-point sizes.
h = scatter(x, y);
set(h, 'SizeData', 40); % uniform size
set(h, 'SizeData', abs(y) * 50); % size proportional to |y|The size unit is points squared, matching MATLAB conventions.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how scatter works, line by line, in Rust.
- View scatter.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.