FUNCTION REFERENCE

surf

3-D surface plot.

3-D surface plot.

Syntax

surf(Z)

Syntax

surf(Z, C)

Syntax

surf(X, Y, Z)

Syntax

surf(X, Y, Z, C)

Syntax

surf(..., Name, Value)

Syntax

surf(ax, ...)

Syntax

h = surf(...)

Draws the surface through the grid points (X(j), Y(i), Z(i,j)) as one surface object of (rows-1)*(columns-1) quadrilateral faces. Z is a real matrix of at least 2-by-2 (at most 1000000 elements); X and Y are vectors with one value per column and per row of Z, or matrices of Z's size; surf(Z) uses X = 1:columns and Y = 1:rows. C (default Z) is the colour data: with FaceColor 'flat' a face takes the CData of its first vertex (row i, column j for the face between rows i..i+1 and columns j..j+1), mapped through the axes colormap with CDataMapping 'scaled'. While CLim is automatic it spans [min max] of the finite CData of every surface in the axes; a CLim set with clim or caxis is kept. colormap, clim and caxis recolour the faces; colorbar shows the mapping.

A face with NaN or Inf in any of its four vertices (X, Y, Z or C) is left out (a hole). Faces are painted far to near by the mean depth of their projected corners (painter's algorithm) after every view change, across all surfaces of the axes. With hold off the axes switches to view(3) = (-37.5, 30); with hold on the current view is kept.

Defaults: FaceColor 'flat', EdgeColor black, LineStyle '-', LineWidth 0.5, FaceAlpha 1, FaceLighting 'flat'. Name-value pairs and h's properties: XData, YData, ZData, CData (setting them redraws), FaceColor ('flat', 'interp', 'none', an RGB triplet or colour name), EdgeColor ('flat', 'interp', 'none', RGB or name), FaceAlpha (scalar 0..1), LineStyle, LineWidth, FaceLighting ('none', 'flat', 'gouraud' or 'phong'), DisplayName and Visible. h.Type is 'surface'. FaceLighting is stored and returned; it does not change the drawn colours. legend lists one entry per surface; .mrfig files keep the face colours, FaceAlpha and the view.

Errors: "surf: Z exceeds 1000000 elements", "surf: Z must be a matrix of at least 2-by-2", "surf: X must be a vector with one value per column of Z, or a matrix of Z's size", "surf: C must be the same size as Z", "surf: the surface needs N faces and the figure already holds M; a figure holds at most 100000 patch faces".

Example

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

Example

h = surf(magic(4)); h.Type   % 'surface'

Example

h = surf(magic(4)); h.FaceAlpha = 0.5; h.EdgeColor = 'none';

Differences from MATLAB: FaceColor and EdgeColor 'interp' are approximated: each face (or face outline) takes the mean of its four vertices' mapped colours, without per-vertex gradients. The depth sort is per face (painter's algorithm), so intersecting faces can overlap wrongly where a depth buffer would cut them. EdgeColor 'flat' draws a face's whole outline in that face's colour. A figure holds at most 100000 patch faces in total (surfaces, contourf bands, patches); low-level patch objects keep their own 10000-face budget. FaceAlpha 'flat'/'interp', AlphaData, CDataMapping 'direct', true-colour CData, material and camlight are not supported yet, nor are surfc, meshc, meshz, waterfall, ribbon and hidden off. FaceLighting does not light the faces. The low-level function is surface.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.