zlabel — Set z-axis label text for current or specified axes with MATLAB-compatible zlabel forms.
zlabel sets or updates z-axis label text and returns a text handle for styling/property edits, following MATLAB-compatible axes-label workflows.
Syntax
h = zlabel(txt)
h = zlabel(ax, txt)
h = zlabel(txt, Name, Value, ...)
h = zlabel(ax, txt, Name, Value, ...)
zlabel(txt)
zlabel(ax, txt)
zlabel(txt, Name, Value, ...)
zlabel(ax, txt, Name, Value, ...)Inputs
txt- Type
Any- Required
- Yes
- Description
- Label text (string/char/cellstr-like multiline forms).
ax- Type
AxesHandle- Required
- Yes
- Description
- Target axes handle.
props- Type
Any- Required
- Variadic
- Description
- Property/value pairs (Color, FontSize, FontWeight, etc.).
Returns
h- Type
NumericScalar- Description
- Handle to the created/updated zlabel object.
Errors
RunMat:zlabel:InvalidArgument- When
- Axes handle, text payload, or property/value arguments are invalid.
- Message
zlabel: invalid argument
RunMat:zlabel:Internal- When
- Internal plotting state update fails.
- Message
zlabel: internal operation failed
RunMat:zlabel:TooManyOutputs- When
- More than one output is requested.
- Message
zlabel: too many output arguments
Behavior
The returned value is a text handle that can be queried and updated through get and set.
String scalars, string arrays, cell arrays, and numeric scalars can be used as label text. Native integer scalars use their exact decimal spelling.
FontSize accepts single, double, and all eight native integer classes; values must be positive and finite.
Z-axis labels are subplot-local and stay attached to the axes they were created for. RunMat mode additionally accepts typed-integer aliases for encoded axes handles.
Placement and execution
This command mutates local graphics scene state and may notify the graphics host. Inputs and returned graphics handles are host-owned; worker transfer of numeric handle values does not transfer scene ownership.
Interpreter and compiled routes use the same runtime operation; a browser graphics host or desktop graphics host is required for presentation.
Examples
Add a z-axis label to a surface plot
[X, Y] = meshgrid(linspace(-3, 3, 50), linspace(-3, 3, 50));
Z = sin(X) .* cos(Y);
surf(X, Y, Z);
zlabel('Height');Create a multiline z-axis label and style it
[X, Y] = meshgrid(-2:0.2:2, -2:0.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X, Y, Z);
h = zlabel(["Depth", "(km)"]);
set(h, 'FontWeight', 'bold');Target a specific subplot axes
[X, Y] = meshgrid(linspace(-3, 3, 30), linspace(-3, 3, 30));
Z = sin(X) .* cos(Y);
subplot(1, 2, 1);
surf(X, Y, Z);
ax = subplot(1, 2, 2);
plot3(cos(0:0.1:5), sin(0:0.1:5), 0:0.1:5);
zlabel(ax, 'Trajectory Height');Using zlabel with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how zlabel changes the result.
Run a small zlabel example, explain the result, then change one input and compare the output.
FAQ
When do I need zlabel vs just xlabel/ylabel?⌄
zlabel only applies to 3-D axes — surf, mesh, plot3, scatter3, etc. For 2-D plots, the z-axis doesn't exist, so zlabel has no effect. If you're plotting in 3-D, always label all three axes so readers can orient themselves.
Can I use LaTeX formatting in zlabel?⌄
You can use LaTeX-style inline math in the label string with standard TeX markup. Subscripts, superscripts, and Greek letters work in label text.
zlabel('Temperature (\circC)');
zlabel('\sigma_{z} (MPa)');How do I style the z-axis label after creating it?⌄
zlabel returns a text handle that works with get and set. You can change font weight, size, color, and other text properties through that handle.
h = zlabel('Elevation (m)');
set(h, 'FontWeight', 'bold', 'FontSize', 14);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 zlabel is executed, line by line, in Rust.
- View the source for zlabel 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.