{
"title": "zlabel",
"category": "plotting",
"keywords": [
"zlabel",
"z-axis label",
"3-D axis label",
"matlab zlabel",
"surface axis labeling"
],
"summary": "Set z-axis labels for 3-D plots, surfaces, and MATLAB `zlabel` workflows.",
"requires_feature": null,
"tested": {
"unit": "builtins::plotting::zlabel::tests"
},
"description": "`zlabel` sets or updates the z-axis label for the current axes or an explicit axes handle. In RunMat it returns a text handle, stores the label as subplot-local axes metadata, and supports the same multiline/property workflows as the other shared text builtins used for titles and axis labels.",
"behaviors": [
"The returned value is a text handle that can be queried and updated through `get` and `set`.",
"String scalars, string arrays, and cell arrays can all be used to build multiline z-axis labels in MATLAB-style workflows.",
"Font and text styling properties flow through the shared plotting text-property system, so `get` and `set` work on the returned handle.",
"Z-axis labels are subplot-local and stay attached to the axes they were created for."
],
"examples": [
{
"description": "Add a z-axis label to a surface plot",
"input": "[X, Y] = meshgrid(linspace(-3, 3, 50), linspace(-3, 3, 50));\nZ = sin(X) .* cos(Y);\nsurf(X, Y, Z);\nzlabel('Height');"
},
{
"description": "Create a multiline z-axis label and style it",
"input": "[X, Y] = meshgrid(-2:0.2:2, -2:0.2:2);\nZ = X .* exp(-X.^2 - Y.^2);\nsurf(X, Y, Z);\nh = zlabel([\"Depth\", \"(km)\"]);\nset(h, 'FontWeight', 'bold');"
},
{
"description": "Target a specific subplot axes",
"input": "[X, Y] = meshgrid(linspace(-3, 3, 30), linspace(-3, 3, 30));\nZ = sin(X) .* cos(Y);\nsubplot(1, 2, 1);\nsurf(X, Y, Z);\nax = subplot(1, 2, 2);\nplot3(cos(0:0.1:5), sin(0:0.1:5), 0:0.1:5);\nzlabel(ax, 'Trajectory Height');"
}
],
"faqs": [
{
"question": "When do I need zlabel vs just xlabel/ylabel?",
"answer": "`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."
},
{
"question": "Can I use LaTeX formatting in zlabel?",
"answer": "You can use LaTeX-style inline math in the label string with standard TeX markup. Subscripts, superscripts, and Greek letters work in label text.\n\n```matlab\nzlabel('Temperature (\\circC)');\nzlabel('\\sigma_{z} (MPa)');\n```"
},
{
"question": "How do I style the z-axis label after creating it?",
"answer": "`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.\n\n```matlab\nh = zlabel('Elevation (m)');\nset(h, 'FontWeight', 'bold', 'FontSize', 14);\n```"
}
],
"links": [
{
"label": "view",
"url": "./view"
},
{
"label": "plot3",
"url": "./plot3"
},
{
"label": "surf",
"url": "./surf"
},
{
"label": "get",
"url": "./get"
},
{
"label": "set",
"url": "./set"
},
{
"label": "Choosing the right plot type",
"url": "/docs/plotting/choosing-the-right-plot-type"
},
{
"label": "Styling plots and axes",
"url": "/docs/plotting/styling-plots-and-axes"
},
{
"label": "Plot replay and export",
"url": "/docs/plotting/plot-replay-and-export"
},
{
"label": "Complete plotting guide",
"url": "/blog/matlab-plotting-guide"
}
],
"source": {
"label": "`crates/runmat-runtime/src/builtins/plotting/ops/zlabel.rs`",
"url": "https://github.com/runmat-org/runmat/blob/main/crates/runmat-runtime/src/builtins/plotting/ops/zlabel.rs"
}
}