5 MATLAB 3D Plot Examples Explained with Code and Colors (2024)

5 MATLAB 3D Plot Examples Explained with Code and Colors (1)

Did you ever wonder seeing amazing 3D graphs in MATLAB? How to draw multiple 3D plot graphs in MATLAB?

This is an in-depth tutorial for you. I will explain the different MATLAB 3D plot examples and how to draw them.

This tutorial is an extension of a previous tutorial two-dimensional [2D] MATLAB plot.

When I share the 2D plot graph tutorial, some of the readers asked me about the 3D plot. And I decided to write about it.

This tutorial provides you the plot’s functions, syntax, and code, for example for the five main different types of 3D plots. At the end of this post, you will be able to draw your own 3D plot graph in MATLAB.

It’s amazing. Right?

Let’s start.

3D MATLAB Plot Introduction

In general, the three-dimensional plots consist of the three vectors (x,y,z) in the same graph.

In MATLAB, the plot3() function is used to draw the 3D plot graph. You can also use a specified line style, marker, and color for drawing 3D plots.

The general syntax to display the 3D plot is,

plot3(x,y,z)plot3(x,y,z,Name)plot3(x,y,z,LineSpec)

Let’s start drawing different types of the 3D plot graph…

Classifications of Three-Dimensional Plots | MATLAB 3D plot Examples

Here, we are considering, the five main different types of three-dimensional (3D) plots. These graphs are mostly used in the industry.

The following list of different 3D plots as,

  1. Mesh Plot
  2. Surface Plot
  3. Ribbon PLot
  4. Contour Plot
  5. Slice Plot

As a part of this tutorial about MATLAB 3D plot examples, I am describing the topmost five 3D plots one-by-one.

1. Mesh 3D Plot in MATLAB

The mesh plotting function is used to display the mesh plot. It produces a wireframe surface where the lines connecting the defining points are colored.

How to create the Mesh plot in MATLAB?

For the mesh plotting in MATLAB, you need to pass the array values to the mesh function.

Syntax:

Mesh function transforms the domain specified by vectors (X, Y, Z) into arrays (x,y,z).

The syntax for the Mesh Plot is,

mesh(x,y,z)[X,Y,Z] = meshgrid(x,y,z)

MATLAB Code:

As an example, we are plotting the mesh 3D plot for square root mathematical function.

[x,y] = meshgrid(-10:0.1:10); t = sqrt(x.^2+y.^2);z =(10*sin(t));mesh(x,y,z)

Output in MATLAB:

See here, you get a colorful and smooth connecting surface line of three-dimensional [3D] Mesh plot.

5 MATLAB 3D Plot Examples Explained with Code and Colors (2)

You can also plot the graph for various Mathematical Expressions in MATLAB.

2. Surface 3D Plot in MATLAB

A surface plot is somewhat similar to a mesh plot. The main difference between them is, in the surface plot, the connecting lines and the faces both will be displayed in the dark color.

How to create the Surf plot in MATLAB?

Syntax:

In the surface plot, ‘surf’ function is used. So, you can write a simple format like ‘function name(array)’.

surf(x,y,z)surf(z)

MATLAB Code:

Let’s write a MATLAB code for the three-dimensional surface plot for an exponential function exp().

[x,y] = peaks(30);z = exp(-0.9*(x.^2+0.5*(x-y).^2));surf(x,y,z);xlabel('\bf X axis');ylabel('\bf Y axis');zlabel('\bf Z axis');title('\bf Surface Plot')colorbar

Output in MATLAB:

After the getting output of surface plot, you will see the connecting lines and the faces are both displayed in the same shade.

5 MATLAB 3D Plot Examples Explained with Code and Colors (3)

3. Ribbon 3D Plot in MATLAB

As the name ribbon, this 3D plot graph will be having different color ribbons.

How to create the ribbon plot in MATLAB?

Here, we are using ribbon() function for plotting ribbon 3D MATLAB plot.

Syntax:

The general syntax for writing code,

ribbon(x,y,z)ribbon(x,y)ribbon(z)

MATLAB Code:

To create a ribbon plot using peak function for mathematical function ((x²)-(y²))

[x,y] = peaks(30);z =[(x.^2)-(y.^2)];ribbon(z);title('\bf Ribbon Plot')

Output in MATLAB:

You can see each and every colorful shade ribbons.

5 MATLAB 3D Plot Examples Explained with Code and Colors (4)

4. Contour 3D Plot in MATLAB

How to create the three dimensional [3D] contour plot?

To create the three dimensional [3D] contour plot, we are using the ‘contour3’ function.

Note: You can plot the Contour 2D plot by using the only ‘contour’ function.

Syntax:

The syntax for the three-dimensional contour plot,

contour3(x,y,z)contour3(z)

MATLAB Code:

We are plotting the contour plot for the exponential mathematical equation is (exp( x²-y²)).

[x,y] = peaks(30);z = exp(-x.^2-y.^2);contour3(x,y,z);title('\bf Contour Plot')

Output in MATLAB:

Below is a diagram for three dimensional [3D] contour plot.

5 MATLAB 3D Plot Examples Explained with Code and Colors (5)

5. Slice 3D Plot in MATLAB

For plotting slice graph, you must know volumetric data(v), specification of three-dimensional coordinate (x,y,z), and ‘xslice, yslice, zslice’.

Syntax:

Slice plot’s syntax is

slice(x,y,z,v,xslice,yslice,zslice)slice(v,xslice,yslice,zslice)

Where,

  • xslice- ‘x’ coordinate data for slice plot
  • yslice- ‘y’ coordinate data for slice plot
  • zslice- ‘z’ coordinate data for slice plot

MATLAB Code:

Slice plot is little different from other 3D plots types. When you are writing MATLAB code for Slice plot, you need to specify each coordinator value.

Let’s draw the slite plot graph for an exponential mathematical equation.

[x,y,z] = meshgrid(-10:.2:10);v = [exp((x.^2)-(y.^3)-(z.^5))];xslice = 0.1; yslice = 5;zslice = 0;slice(x,y,z,v,xslice,yslice,zslice)colorbartitle('\bf Slice Plot')

Output in MATLAB:

The output looks like the below picture.

5 MATLAB 3D Plot Examples Explained with Code and Colors (6)

These are the topmost three dimensional [3D] used in the industry projects.

This is all about different MATLAB 3D plot examples. I have explained the different classification of MATLAB 3D plots with simple code and syntax.

If you have doubt, write in the comment. I will reply to you as soon as possible.

Other MATLAB Tutorials:

  • MATLAB Math Functions
  • MATLAB M-File Details
  • Matrix in MATLAB
  • Vector in MATLAB
  • MATLAB/ Simulink Toolbox
  • Application of MATLAB/Simulink

Thanks for Reading!

Are you looking for job?

Job openings »

5 MATLAB 3D Plot Examples Explained with Code and Colors (7)

Dipali Chaudhari

I have completed master in Electrical Power System. I work and write technical tutorials on the PLC, MATLAB programming, and Electrical on DipsLab.com portal.

Sharing my knowledge on this blog makes me happy. And sometimes I delve in Python programming.

5 MATLAB 3D Plot Examples Explained with Code and Colors (2024)

FAQs

What is an example of a 3-D plot in MATLAB? ›

Example: plot3(tbl,"x",["y1","y2"],"z") specifies the table variables named y1 and y2 for the y-coordinates. Example: plot3(tbl,"x",2,"z") specifies the second variable for the y-coordinates. Example: plot3(tbl,"x",vartype("numeric"),"z") specifies all numeric variables for the y-coordinates.

How do you change the color of a 3-D plot in MATLAB? ›

Here is the code:
  1. t = 0:0.1:60;
  2. x = 20*t; y = cos(t); z = sin(t);
  3. view(3);
  4. color=jet(size(t,2));
  5. close all.
  6. for i=1:size(t,2)
  7. plot3(x(1:1:i),y(1:1:i),z(1:1:i),'color',color(i,:))
  8. axis([0 1800.7 -1.7 1.7 -1.3 1.3])
Jan 12, 2022

How to plot 3-D equations in MATLAB? ›

3-D function to plot, specified as a function handle to a named or anonymous function. Specify a function of the form z = f(x,y) . The function must accept two matrix input arguments and return a matrix output argument of the same size.

How do you plot a graph in different colors in MATLAB? ›

thisIndex = ceil(row/5); thisColor = plotColors(thisIndex, :); plot(thisX, thisY, '-', 'Color', thisColor, 'LineWidth', 2); hold on; % Leave plots up so we'll see all of them at the end.

How to plot a 3D graph? ›

In order to plot 3D figures use matplotlib, we need to import the mplot3d toolkit, which adds the simple 3D plotting capabilities to matplotlib. Once we imported the mplot3d toolkit, we could create 3D axes and add data to the axes. Let's first create a 3D axes.

How do you change the color of 3-D? ›

Right-click in the drawing area, and choose Properties. In the Properties palette, click Color, and then click the down arrow. From the drop-down list, choose the color that you want to assign to the objects.

How to use RGB colors in MATLAB plot? ›

RGB Triplet — Create a custom color by specifying a three-element row vector whose elements are the intensities of the red, green, and blue components of a color. The intensities must be in the range [0,1] . For example, you can specify a shade of pink as [1 0.5 0.8] .

How do you change the color of a plot? ›

To change the color of a plot, simply add a color parameter to the plot function and specify the value of the color.

How to create a 3D model in MATLAB? ›

Accepted Answer

In MATLAB, the patch function can be used to generate a 3D model by specifying the vertices and faces of the object. This function provides a convenient way to plot and visualize 3D objects in MATLAB. patch('Vertices', vertices, 'Faces', faces, 'FaceColor','red');

How to plot surface in 3-D MATLAB? ›

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. Specify the axes as the first input argument.

What does plot3 function do in MATLAB? ›

The plot3 function displays a three-dimensional plot of a set of data points. plot3(X1,Y1,Z1,...), where X1 , Y1 , Z1 are vectors or matrices, plots one or more lines in three-dimensional space through the points whose coordinates are the elements of X1 , Y1 , and Z1 .

What is a plot 3 dimensional function? ›

Plot3D is also known as a surface plot or surface graph. Plot3D evaluates f at values of x and y in the domain being plotted over and connects the points {x,y,f[x,y]} to form a surface showing how f varies with x and y. It visualizes the surface .

What is a 3 dimensional surface plot? ›

Use 3D Surface Plot to examine the relationship between a response variable (Z) and two predictor variables (X and Y), by viewing a three-dimensional surface of the predicted response. You can choose to represent the predicted response as a smooth surface or a wireframe.

How to make a 3-D array in MATLAB? ›

You can create a multidimensional array by creating a 2-D matrix first, and then extending it. For example, first define a 3-by-3 matrix as the first page in a 3-D array. Now add a second page. To do this, assign another 3-by-3 matrix to the index value 2 in the third dimension.

Top Articles
20 Super Bowl Sonntagsgeschenke für Sport- und Spielbegeisterte
Ackee and Saltfish Recipe - National Jamaican Dish
Barbara Roufs Measurements
Ess Compass Associate Portal Login
Cvs Rt Pcr Test
Casa Grande Az Craigslist
Anonib Altoona Pa
Leon Vs Chisec Figs
Julia Is A Doctor Who Treats Patients
Busted Newspaper Hart County Ky
Sauce 423405
Sand Castle Parents Guide
Zack Fairhurst Snapchat
The Woman King Showtimes Near Cinemark 14 Lancaster
Ups Customer Center Locations
Offres Emploi Purchasing manager Paris (75000) | HelloWork
102Km To Mph
Food Universe Near Me Circular
No Prob-Llama Plotting Points
Selfservice Bright Lending
Amex Platinum Cardholders: Get Up to 10¢ Off Each Gallon of Gas via Walmart Plus Gas Discount
1970 Baltimore Orioles World Series Scroll Pennant
Tv Guide Visalia
Check Subdomains Of A Domain
Point After Salon
Belly Button Torture Video
Pa Lottery Remaining Prizes Scratch Offs
Shellys Earth Materials
Verizon Fios Internet Review: Plans, Prices And Speed 2024
Dki Brain Teaser
Dfw Rainfall Last 72 Hours
Trailmaster Fahrwerk - nivatechnik.de
Alineaciones De Rcd Espanyol Contra Celta De Vigo
Fgo Rabbit Review
The Meaning Behind The Song: 4th & Vine by Sinéad O'Connor - Beat Crave
Craigslist Creative Gigs
Bank Of America Financial Center Irvington Photos
African American Thursday Blessings Gif
Family Link from Google - Family Safety & Parental Control Tools
Tampa Catholic Calendar
Beacon Schneider La Porte
4Myhr Mhub
Slmd Skincare Appointment
Russia Ukraine war live: Starmer meets Biden at White House but no decision on Ukraine missiles
Ups Customer Center Locations
Sona Systems Tcu
Poopybarbz
Fraction Button On Ti-84 Plus Ce
Tokyo Spa Memphis Tn Reviews
Codex Genestealer Cults 10th Edition: The Goonhammer Review
Guy Ritchie's The Covenant Showtimes Near Century 16 Eastport Plaza
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 6117

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.