Surface plot - MATLAB surf (2024)

Surface plot

collapse all in page

  • Surface plot - MATLAB surf (1)

Syntax

surf(X,Y,Z)

surf(X,Y,Z,C)

surf(Z)

surf(Z,C)

surf(ax,___)

surf(___,Name,Value)

s = surf(___)

Description

example

surf(X,Y,Z) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y. The color of the surface varies according to the heights specified by Z.

example

surf(X,Y,Z,C) additionallyspecifies the surface color.

surf(Z) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates.

surf(Z,C) additionallyspecifies the surface color.

surf(ax,___) plotsinto the axes specified by ax instead of the currentaxes. Specify the axes as the first input argument.

example

surf(___,Name,Value) specifies surface properties using one or more name-value pair arguments. For example, 'FaceAlpha',0.5 creates a semitransparent surface.

example

s = surf(___) returns the chart surface object. Use s to modify the surface after it is created. For a list of properties, see Surface Properties.

Examples

collapse all

Create Surface Plot

Open Live Script

Create three matrices of the same size. Then plot them as a surface. The surface plot uses Z for both height and color.

[X,Y] = meshgrid(1:0.5:10,1:20);Z = sin(X) + cos(Y);surf(X,Y,Z)

Surface plot - MATLAB surf (2)

Specify Colormap Colors for Surface Plot

Open Live Script

Specify the colors for a surface plot by including a fourth matrix input, C. The surface plot uses Z for height and C for color. Specify the colors using a colormap, which uses single numbers to stand for colors on a spectrum. When you use a colormap, C is the same size as Z. Add a color bar to the graph to show how the data values in C correspond to the colors in the colormap.

[X,Y] = meshgrid(1:0.5:10,1:20);Z = sin(X) + cos(Y);C = X.*Y;surf(X,Y,Z,C)colorbar

Surface plot - MATLAB surf (3)

Specify True Colors for Surface Plot

Open Live Script

Specify the colors for a surface plot by including a fourth matrix input, CO. The surface plot uses Z for height and CO for color. Specify the colors using truecolor, which uses triplets of numbers to stand for all possible colors. When you use truecolor, if Z is m-by-n, then CO is m-by-n-by-3. The first page of the array indicates the red component for each color, the second page indicates the green component, and the third page indicates the blue component.

[X,Y,Z] = peaks(25);CO(:,:,1) = zeros(25); % redCO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % greenCO(:,:,3) = ones(25).*linspace(0,1,25); % bluesurf(X,Y,Z,CO)

Surface plot - MATLAB surf (4)

Modify Surface Plot Appearance

Open Live Script

Create a semitransparent surface by specifying the FaceAlpha name-value pair with 0.5 as the value. To allow further modifications, assign the surface object to the variable s.

[X,Y] = meshgrid(-5:.5:5);Z = Y.*sin(X) - X.*cos(Y);s = surf(X,Y,Z,'FaceAlpha',0.5)

Surface plot - MATLAB surf (5)

s = Surface with properties: EdgeColor: [0 0 0] LineStyle: '-' FaceColor: 'flat' FaceLighting: 'flat' FaceAlpha: 0.5000 XData: [21x21 double] YData: [21x21 double] ZData: [21x21 double] CData: [21x21 double] Use GET to show all properties

Use s to access and modify properties of the surface object after it is created. For example, hide the edges by setting the EdgeColor property.

s.EdgeColor = 'none';

Surface plot - MATLAB surf (6)

Input Arguments

collapse all

Xx-coordinates
matrix | vector

x-coordinates, specified as a matrix the same size as Z, or as a vector with length n, where [m,n] = size(Z). If you do not specify values for X and Y, surf uses the vectors (1:n) and (1:m).

You can use the meshgrid function to create X and Y matrices.

The XData property of the Surface object stores the x-coordinates.

Example: X = 1:10

Example: X = [1 2 3; 1 2 3; 1 2 3]

Example: [X,Y] = meshgrid(-5:0.5:5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Yy-coordinates
matrix | vector

y-coordinates, specified as a matrix the same size as Z or as a vector with length m, where [m,n] = size(Z). If you do not specify values for X and Y, surf uses the vectors (1:n) and (1:m).

You can use the meshgrid function to create the X and Y matrices.

The YData property of the surface object stores the y -coordinates.

Example: Y = 1:10

Example: Y = [1 1 1; 2 2 2; 3 3 3]

Example: [X,Y] = meshgrid(-5:0.5:5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Zz-coordinates
matrix

z-coordinates, specified as a matrix. Z must have at least two rows and two columns.

Z specifies the height of the surface plot at each x-y coordinate. If you do not specify the colors, then Z also specifies the surface colors.

The ZData property of the surface object stores the z -coordinates.

Example: Z = [1 2 3; 4 5 6]

Example: Z = sin(x) + cos(y)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

CColor array
matrix | m-by-n-by-3 array of RGB triplets

Color array, specified as an m-by-n matrix of colormap indices or as an m-by-n-by-3 array of RGB triplets, where Z is m-by-n.

  • To use colormap colors, specify C as a matrix. For each grid point on the surface, C indicates a color in the colormap. The CDataMapping property of the surface object controls how the values in C correspond to colors in the colormap.

  • To use truecolor colors, specify C as an array of RGB triplets.

For more information, see Differences Between Colormaps and Truecolor.

The CData property of the surface object stores the color array. For additional control over the surface coloring, use the FaceColor and EdgeColor properties.

axAxes to plot in
axes object

Axes to plot in, specified as an axes object. If you do not specify the axes, then surf plots into the current axes.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: surf(X,Y,Z,'FaceAlpha',0.5,'EdgeColor','none') createsa semitransparent surface with no edges drawn.

Note

The properties listed here are only a subset. For a full list,see Surface Properties.

Extended Capabilities

Version History

Introduced before R2006a

See Also

Functions

  • colormap | pcolor | meshgrid | imagesc | shading | view | mesh

Properties

  • Surface Properties

Topics

  • Representing Data as a Surface
  • How Surface Plot Data Relates to a Colormap

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Surface plot - MATLAB surf (7)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Surface plot - MATLAB surf (2024)

FAQs

What is the difference between Ezsurf and surf in MATLAB? ›

The ezsurf function does not plot points where the mathematical function is not defined. These points are set to NaN so that they do not plot. Use surf to plot the same data without filtering discontinuities.

Why is my surf plot all black in MATLAB? ›

The issue occurs when the grid which your surface is plotted over contains a large number of points. The lines which create the wire mesh surface are black by default and take precedence over the color map. In this situation, the wire grid is so dense that the lines form a completely black surface.

How to plot using surf in MATLAB? ›

surf( X , Y , Z , C ) additionally specifies the surface color. surf( Z ) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates. surf( Z , C ) additionally specifies the surface color. surf( ax ,___) plots into the axes specified by ax instead of the current axes.

How do I get rid of black lines in MATLAB surf plot? ›

To fix it you can use a coarser grid, if that's an option, or you can turn the grid lines off by specifying 'EdgeColor','none' when the surface is created (or after it's created). Here's your code but with 'EdgeColor','none' in second call to surf.

What is the difference between mesh and surf in MATLAB? ›

The difference is that, surf creates kind of a solid surface, whereas mesh creates a surface formed by a "mesh" of "wires".

What is the difference between a surface plot and a mesh plot? ›

Mesh plots Page 8 - are wire-frame surfaces that color only the lines connecting the defining points. Surface plots - display both the connecting lines and the faces of the surface in color. The mesh and surf commands create 3-D surface plots of matrix data.

How do I make my MATLAB plot better? ›

Direct link to this comment
  1. Increase the linewidth (2 or 3 is good).
  2. Add a grid.
  3. Add minor ticks to the axes.
  4. Plot as an area with solid line and semi-transparent fill.
  5. Set the axes limits appropriately.
  6. Add a legend.
  7. Change the font and fontsize to match the output size.
  8. Set the figure aspect ratio correctly.
Feb 27, 2016

How do I make my surf transparent in MATLAB? ›

Set the properties to a scalar value in the range [0,1] . A value of 0 means completely transparent, a value of 1 means completely opaque, and values between 0 and 1 are semitransparent. Patch, surface, scatter, and image objects support using alpha data to vary the transparency across the object.

What is the default view surf in MATLAB? ›

Default 2-D and 3-D Views

MATLAB automatically selects a viewpoint that is determined by whether the plot is 2-D or 3-D: For 2-D plots, the default is azimuth = 0° and elevation = 90°. For 3-D plots, the default is azimuth = -37.5° and elevation = 30°.

What is the difference between a surface plot and a contour plot? ›

A comparison of contour plots and 3D surface plots

Contour plots are useful for establishing the response values and operating conditions that you want. A 3D surface plot displays a 3-dimensional view of the surface.

What is the surface of a plot in MATLAB? ›

MATLAB® graphics defines a surface by the z-coordinates of points above a rectangular grid in the x-y plane. The plot is formed by joining adjacent points with straight lines. Surface plots are useful for visualizing matrices that are too large to display in numerical form and for graphing functions of two variables.

What is a surface plot? ›

Introduction. Surface plots are diagrams of three-dimensional data. Rather than showing the individual data points, surface plots show a functional relationship between a designated dependent variable (Y), and two independent variables (X and Z). The plot is a companion plot to the contour plot.

How do I change the color of my surf plot in MATLAB? ›

MATLAB® uses a default color scheme when it displays visualizations such as surface plots. You can change the color scheme by specifying a colormap. Colormaps are three-column arrays containing RGB triplets in which each row defines a distinct color.

How do I get rid of horizontal black lines? ›

Remove a horizontal line
  1. Place the cursor immediately above the horizontal line.
  2. On the Home tab, click the arrow next to the Borders and Shading button, and click No Border.

How do I get rid of display lines? ›

How to fix vertical or horizontal lines on an Android screen
  1. Check for software updates. Software updates are your phone's defense against known display issues. ...
  2. Put your phone in Safe Mode. ...
  3. Complete a factory reset. ...
  4. Consider internal damage.
Mar 21, 2024

What is Ezsurf in MATLAB? ›

ezsurf(___,'circ') creates the surface plot over a disk centered on the range. You can specify 'circ' after the input arguments in any of the previous syntaxes. h = ezsurf(___) returns a handle h to the surface plot object. You can use the output argument h with any of the previous syntaxes.

What is the difference between skim and surf? ›

Skim riders typically prefer a longer, less steep wave with a trick-saving pocket that goes way back, which generally means a more bow-weighted boat. Conversely, surf-style riders usually appreciate a steep, tall, powerful wave, produced by a mostly stern-weighted boat.

What is the difference between surfing and browsing? ›

Browsing is looking or searching for specific information on the Internet with a purpose. Surfing is looking for information on the Internet with no apparent goal. Surfing is a casual search in an undirected manner, but a person does browsing with an aim and a direction.

What is a surf plot? ›

Surface plots are diagrams of three-dimensional data. Rather than showing the individual data points, surface plots show a functional relationship between a designated dependent variable (Y), and two independent variables (X and Z).

References

Top Articles
10 Dinge, die euch den Start in Fractured Online erleichtern
Fractured Online: Ersteindruck - Riesiges Potential in wackeliger Verpackung
9Anime Keeps Buffering
19 Awesome Things to Do in Redmond, Oregon
Monthly Weather Calendar
Zavvi Discount Code → 55% Off in September 2024
Gateway Login Georgia Client Id
The KT extinction
Saxies Lake Worth
50 Cent – Baby By Me (feat. Ne-Yo) ఆంగ్ల లిరిక్స్ & రంగుల అనేక. అనువాదాలు - lyrics | çevirce
Best NBA 2K23 Builds for Every Position
The 10 Best Drury Hotels in the United States
Top Scorers Transfermarkt
Teenbeautyfitness
Kamala Harris is making climate action patriotic. It just might work
Las mentiras y los crímenes que continúan. 9.11 X Veintitrés = Sin palabras
Caribbean Mix Lake Ozark
How Much Is 7 Million Pesos
Somewhere In Queens Showtimes Near The Maple Theater
Glenwood Apartments Logan Utah
Patriot Ledger Obits Today
Gas Buddy Prices Near Me Zip Code
Kamala Harris, Donald Trump debate prompts major endorsem*nt, Fox News invitation for a 2nd face-off
Elmira Star Gazette Obit
Edt National Board
Lewelling Garden Supply
Hyvee Workday
Course schedule | Fall 2022 | Office of the Registrar
Xdm16Bt Manual
Shruti Rajagopalan — On Spotting Talent, And Making Sense of Rising India (#152)
Bellagio Underground Tour Lobby
Ralph Macchio Conservative
Leesburg Regional Medical Center Medical Records
Imperialism Flocabulary Quiz Answers
Diablo 3 Metascore
Hingham Police Scanner Wicked Local
5Gomovies
Tyrone Unblocked Games Bitlife
Liv Morgan Wedgie
Walgreens Wellington Green
Elaina Scotto Wedding
Incident Manager (POS & Kiosk) job in Chicago, IL with McDonald's - Corporate
Sam's Club Hiring Near Me
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
55000 Pennies To Dollars
Hooda Math—Games, Features, and Benefits — Mashup Math
Bbc Numberblocks
Best Blox Fruit For Grinding
18K Gersc Stamped Inside Ring
Neuer Extraction-Shooter auf Steam will Escape from Tarkov Konkurrenz machen, wird von echten Militär-Veteranen entwickelt
Choices’ summer movie preview
Lenscrafters Westchester Mall
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 6181

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.