plot3 — Create 3-D line plots in MATLAB and RunMat.
plot3 creates line plots in 3-D space from matching x, y, and z inputs. Returned handle behavior and plotting integration follow MATLAB semantics.
Syntax
h = plot3(X, Y, Z)
h = plot3(X, Y, Z, LineSpec)
h = plot3(X, Y, Z, Name, Value, ...)
h = plot3(ax, X, Y, Z)
h = plot3(ax, X, Y, Z, LineSpec)
h = plot3(ax, X, Y, Z, Name, Value, ...)
h = plot3(X1, Y1, Z1, ..., Xn, Yn, Zn)
h = plot3(ax, X1, Y1, Z1, ..., Xn, Yn, Zn)Inputs
X- Type
NumericArray- Required
- Yes
- Description
- X data.
Y- Type
NumericArray- Required
- Yes
- Description
- Y data.
Z- Type
NumericArray- Required
- Yes
- Description
- Z data.
lineSpec- Type
StyleSpec- Required
- Yes
- Description
- Line style/color shorthand.
props- Type
Any- Required
- Variadic
- Description
- Name/value style properties.
ax- Type
AxesHandle- Required
- Yes
- Description
- Target axes handle.
series- Type
Any- Required
- Variadic
- Description
- Interleaved X/Y/Z series triplets with optional per-series style tokens.
Returns
h- Type
NumericScalar- Description
- Handle to the first 3-D line object in the rendered series.
Errors
RunMat:plot3:InvalidArgument- When
- Input data, series grammar, axes targeting, or style arguments are invalid.
- Message
plot3: invalid argument
RunMat:plot3:Internal- When
- Internal 3-D line construction or rendering fails unexpectedly.
- Message
plot3: internal operation failed
Behavior
plot3(x, y, z) requires matching element counts in all three inputs.
The builtin returns a 3-D line handle that can be inspected and updated through get and set.
Multiple 3-D series in one call create multiple line objects and return the handle for the first created series.
plot3 is camera-aware and naturally pairs with view and zlabel in the subplot-local 3-D state model.
GPU-backed 3-D line rendering is used when the shared plotting device can consume exported buffers directly.
Rendering and residency
plot3 uses the dedicated 3-D line rendering path and can keep plotting-compatible GPU inputs resident on device.
plot3 preserves GPU residency for multi-point GPU coordinate inputs when the 3-D line pipeline can consume exported buffers directly. Single-point GPU inputs gather once because they render through the scatter-style point fallback rather than the line-segment packer.
The dedicated 3-D line pipeline is separate from 2-D plot, which keeps camera-aware rendering and bounds handling explicit.
Subview state, labels, and line object behavior remain identical across GPU and host fallback paths.
Plot replay/export can read back preserved GPU source buffers from the line object when host coordinate vectors were not materialized at construction time.
Direct floating rendering precisions
single
double
Coordinate broadcasting
none
Runtime contract and boundaries
The result is a host graphics handle, not a numeric coordinate array. Coordinate parsing, native source storage, series expansion, style validation and graphics state use the existing plotting owners. Numeric handle aliases are resolved at Runtime, so static inference does not guess that a scalar coordinate denotes axes. The line, bar, barh and area constructors may return a row of handles; the other identities return the first created handle. More than one language output is rejected before chart work.
Single and double source data use their native storage where the chart has typed source properties; all eight integer classes use the declared identity-specific coordinate/control rules. Rendering is an explicit floating geometry boundary. In particular errorbar, bar, barh and area convert client graphics data to floating geometry; this does not certify exact integer-valued rendered pixels. Complex, logical, sparse, empty and matrix admission is decided by each existing numerical/shape parser, not by this shared ingress. Unsupported representations raise the existing parser diagnostic rather than being assumed fully MATLAB compatible.
Direct GPU rendering is conditional on the actual owning provider, live physical input leases, floating class/storage, supported shape/style, compatible shared device exports and native plotting feature availability. A pre-effect unavailable direct route may take the existing client path; a failed or partially completed export/reduction/emission is terminal and never permission to replay on the host. Source-property reads and figure persistence can perform later explicit readback. There is no elementwise/reduction fusion, distributed execution or portable numeric provider kernel for these graphics sinks.
User-interface capability and host-callback effects describe graphics creation/presentation, not numeric purity. Portable Runtime linking and an ordinary execution stack allow Native and Wasm ingress; actual presentation requires the installed graphics host. Retained chart data, style metadata, renderer buffers and serialization are separate lifetimes. Current chart scratch/state has no complete finite allocation owner: Managed policy is rejected before argument extraction, gather or chart mutation through the existing HostAllocationReceipt authority. Ordinary Unbounded resident and host routes remain available. Issuer/policy/cancellation are fenced before publication and errors carry Never replay. This refusal, unbounded host loops, provider/renderer-private allocations, full property parity and measured performance remain open obligations; Incomplete/Partial is not a completion certificate.
Supported representations and remaining forms
Coordinates use real single/double Tensor storage or native integer storage. Scalar logical coordinates pass through the existing NumericInput double conversion; logical arrays, complex arrays, sparse arrays, categorical and datetime coordinate objects do not have a NumericInput representation and are not implemented by this chart owner.
Each explicit X/Y/Z triple must have equal, nonzero element counts. Repeated triples create ordered series and return the first handle; a matrix triple is one flattened trajectory rather than full MATLAB matrix-column expansion. LineSpec color/line style, LineStyleOrder, LineWidth, DisplayName and visibility are supported. Marker LineSpec/Marker requests are explicitly rejected until Line3 marker rendering exists. Compatible multi-point floating device triples use the direct Line3 preparation owner; single-point device inputs use the established client point fallback.
Examples
Create a 3-D helix
t = linspace(0, 6*pi, 300);
plot3(cos(t), sin(t), t);Plot multiple 3-D trajectories and label them
t = linspace(0, 4*pi, 200);
h1 = plot3(cos(t), sin(t), t);
set(h1, 'DisplayName', 'helix A');
hold on;
h2 = plot3(cos(t), sin(t), -t);
set(h2, 'DisplayName', 'helix B');
legend;Control the camera and z-axis after plotting
t = linspace(0, 4*pi, 150);
h = plot3(cos(t), sin(t), t);
zlabel('Height');
view(45, 20);
get(h, 'Type')Expected output:
ans =
'line'Rendered plot3 example
t = linspace(0, 8*pi, 600);
radius = 1 + 0.12*cos(5*t);
x = radius.*cos(t);
y = radius.*sin(t);
z = linspace(0, 6, 600) + 0.12*sin(3*t);
h = plot3(x, y, z);
set(h, 'LineWidth', 2);
title('Helical Sensor Trajectory');
xlabel('x (m)');
ylabel('y (m)');
zlabel('z (m)');
view(38, 26);
grid on;
axis equal;
Compare this result with other chart types in the plot examples.
Using plot3 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how plot3 changes the result.
Run a small plot3 example, explain the result, then change one input and compare the output.
FAQ
How do I plot a 3-D trajectory from parametric equations?⌄
Generate a parameter vector t, compute x(t), y(t), z(t), and pass all three to plot3. The line connects points in parameter order.
t = linspace(0, 10*pi, 500);
plot3(sin(t), cos(t), t);
zlabel('z');Can I overlay plot3 lines with scatter3 points?⌄
Yes — use hold on between calls. Both plot3 and scatter3 share the same 3-D axes and camera state, so they compose directly.
t = linspace(0, 4*pi, 200);
plot3(cos(t), sin(t), t);
hold on;
scatter3(cos(t(1:20:end)), sin(t(1:20:end)), t(1:20:end));How do I control the camera angle on a plot3 figure?⌄
Call view(az, el) after plotting. az is the azimuth (horizontal rotation) and el is the elevation (vertical tilt), both in degrees. view(3) gives the default 3-D perspective. Camera state is subplot-local, so each subplot can have its own angle.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · autumn · axes · barh · bone · caxis · cla · clf · clim · colorcube · colororder · cool · copper · copyobj · cylinder · daspect · datacursormode · dataTipTextRow · drawnow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · gray · groot · hgload · hgsave · hidden · histogram2 · hold · hot · inferno · isgraphics · ishandle · jet · line · lines · linkaxes · magma · openfig · opengl · pan · parula · patch · pink · plasma · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · spring · stackedplot · subtitle · summer · suptitle · text · textscatter · textscatter3 · triplot · turbo · viridis · waitbar · winter · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
Source you can read
Every RunMat function's source is public. Read exactly how plot3 is executed, line by line, in Rust.
- View the source for plot3 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.