surf

Draws a 3-D surface colored by height.

Category: Graphics > 2-D and 3-D Plots

Syntax

surf(Z)

Draws the surface with heights Z over the grid of indices.

surf(X, Y, Z)

Uses X and Y as the grid coordinates.

surf(X, Y, Z, C)

Colors the surface by C instead of by Z.

surf(___, Name, Value)

Sets properties such as 'EdgeColor' or 'FaceAlpha'.

h = surf(___)

Also returns the surface handle.

Description

Each cell of the grid becomes a colored quadrilateral, with black edges by default. Use shading interp or shading flat to remove the grid lines, colormap to change the colors, and view or the mouse to rotate the plot.

To build the grid for a function of two variables, call meshgrid first and evaluate the function on its output.

Input arguments

X, Y
Vectors or matrices of coordinates. If both are vectors, their lengths must match the columns and rows of Z.
Z
Matrix of heights.
C
Optional color data, the same size as Z, mapped through the colormap.

Output arguments

h
Handle of the surface object.

Example

A smooth bump

[X, Y] = meshgrid(-2:0.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X, Y, Z)
colorbar

In the app, the figure is drawn below the code.

See also

mesh surfc surfl meshgrid contour