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, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
txt | Any | Yes | — | Label text (string/char/cellstr-like multiline forms). |
ax | AxesHandle | Yes | — | Target axes handle. |
props | Any | Variadic | — | Property/value pairs (Color, FontSize, FontWeight, etc.). |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the created/updated zlabel object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:zlabel:InvalidArgument | Axes handle, text payload, or property/value arguments are invalid. | zlabel: invalid argument |
RunMat:zlabel:Internal | Internal plotting state update fails. | zlabel: internal operation failed |
How zlabel works
- The returned value is a text handle that can be queried and updated through
getandset. - String scalars, string arrays, cell arrays, and numeric scalars can be used as label text. Native integer scalars use their exact decimal spelling.
FontSizeaccepts 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.
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 · axes · barh · caxis · cla · clf · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · text · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 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.