Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (2024)

Updated March 13, 2023

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (1)

Introduction to Matlab 3d scatter plot

3 D scatter plots are used to show the relationship between 3 variables on the cartesian coordinates. 3 D scatter plots are used to interpret the spread of data and identify any outliers. Scatter plots are very useful in data science, where relationships in the test data are used to create algorithms to predict the output. In MATLAB, we use the scatter3() function with 3 arguments to create 3D plots. In this topic, we are going to learn about Matlab 3d scatter plot.

ADVERTIsem*nT Popular Course in this categoryMATLAB - Specialization | 5 Course Series | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax of the scatter3 function:

  1. scatter3 (a, b, c)
  2. scatter3 (a, b, c, Z)
  3. scatter3 (a, b, c, Z, Y)

Description of the scatter3 function:

  1. scatter3 (a, b, c) is used to create a scatter plot for the input vectors a, b, c. By default, MATLAB scatter plots the data points as circles
  2. scatter3 (a, b, c, Z) is used to create a scatter plot for the input vectors a, b, c with the circles of the size defined by the argument ‘Z.’
  3. scatter3 (a, b, c, Z, Y) is used to create a scatter plot for the input vectors a, b, c with the circles of the size defined by the argument ‘Z’ and color specified by the argument ’Y.’

Examples of Matlab 3d scatter plot.

Let us now understand the code to use the scatter3 function in MATLAB.

Example #1

In this example, we will use the scatter3 function in its most basic form and plot a sine wave and a co-wave with random noise. Below are the steps to be followed:

  1. Define the random noise
  2. Initialize the sin wave
  3. Initialize the cos wave

Code:

c = linspace(0, 2 * pi, 100);
[Initializing the random noise]a = sin(c) + rand(1, 100);
[Initializing the sine wave]b = cos(c) + rand(1, 100);
[Initializing the cos wave]scatter3(a, b, c)
[Using the scatter3 function to plot the input waves]

This is how our input and output will look like in MATLAB:

Input:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (2)

Output:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (3)

As we can see in the output, we have obtained a 3D scatter plot for our input waves using the scatter3 function.

Example #2

Next, we will learn how to control the size of the circles in the scatter plot generated using the scatter3 function. For this, we will pass the required size as the 4th argument to the scatter3 function.

Code:

c = linspace(0, 2 * pi, 100);
[Initializing the random noise]a = sin(c) + rand(1, 100);
[Initializing the sine wave]b = cos(c) + rand(1, 100);
[Initializing the cos wave]scatter3(a, b, c, 50)
[Using the scatter3 function to plot the input waves. Please note that we have passed ‘50’ as the 4th argument which defines the size of the circles in the plot]

This is how our input and output will look like in MATLAB:

Input:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (4)

Output:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (5)

As we can see in the output, we have obtained a 3D scatter plot for our input waves using the scatter3 function. Also, the size of the circles in the plot is now larger in comparison to the plot in Example 1.

Example #3

In the above two examples, the color of the circles obtained is blue. Let us see how to change this color as per our requirements. In this example, we will plot a logarithmic function and an exponential function with random noise. Below are the steps to be followed:

  1. Define the random noise
  2. Initialize the logarithmic function
  3. Initialize the exponential function

Code:

c = linspace(0, 2 * pi, 100);
[Initializing the random noise]a = log(c) + rand(1, 100);
[Initializing the log function]b = exp(c) + rand(1, 100);
[Initializing the exponential function]scatter3(a, b, c, 50, 'green')
[Using the scatter3 function to plot the input waves. Please note that the argument ‘green’ is used to get the circles of the scatter plot in green color]

This is how our input and output will look like in MATLAB:

Input:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (6)

Output:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (7)

As we can see in the output, we have obtained a 3D scatter plot for our input waves using the scatter3 function. Also, the color of the circles is ‘green’, as expected by us.

We can also get the circles of solid nature rather than transparent. For this, we will pass another argument ‘filled’.

Code:

c = linspace(0, 2 * pi, 100);
[Initializing the random noise]a = log(c) + rand(1, 100);
[Initializing the log function]b = exp(c) + rand(1, 100);
[Initializing the exponential function]scatter3(a, b, c, 50, 'green', 'filled')
[Using the scatter3 function to plot the input waves. Please note that the argument ‘filled’ is used to get the circles of the solid nature]

This is how our input and output will look like in MATLAB:

Input:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (8)

Output:

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (9)

As we can see in the output, we have obtained a 3D scatter plot for our input waves using the scatter3 function. Also, the circles in the plot are of solid nature, as expected by us.

If we want to get the plot in some shape other than the circles, we again pass the required shape as an argument. For example, we can pass ‘star’ as an argument to create the plots using the ‘star’ shape.

Conclusion

  1. The scatter3 function is used in MATLAB to plot 3D scatter plots
  2. These plots are used to draw 3 variables in one plot
  3. We can control the size, shape and other properties of the plotted points using the arguments of the scatter3 function

Recommended Articles

This is a guide to Matlab 3d scatter plot. Here we discuss the Examples of Matlab 3d scatter plot along with the code to use the scatter3 function in MATLAB. You may also have a look at the following articles to learn more –

  1. What is Matlab?
  2. Nyquist Matlab
  3. Plot graph Matlab
  4. Arctan Matlab

ADVERTIsem*nT

SPSS - Specialization | 14 Course Series | 5 Mock Tests 42 of HD Videos 14 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

MICROSOFT AZURE - Specialization | 15 Course Series | 12 Mock Tests 73 of HD Videos 15 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

HADOOP - Specialization | 32 Course Series | 4 Mock Tests 170 of HD Videos 32 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

INFORMATICA - Specialization | 7 Course Series 69 of HD Videos 7 Courses Verifiable Certificate of Completion Lifetime Access4.5
Primary Sidebar

");jQuery('.cal-tbl table').unwrap("

");jQuery("#mobilenav").parent("p").css("margin","0");jQuery("#mobilenav .fa-bars").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").addClass("showfix-bar");/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-close fa fa-bars');});jQuery("#mobilenav .fa-close").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").removeClass("showfix-bar");jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-bars fa fa-close');/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/});});

Matlab 3d scatter plot | Learn the Examples of Matlab 3d scatter plot (2024)

FAQs

What are scatter plots in MATLAB? ›

A scatter plot is a simple plot of one variable against another. The MATLAB® functions plot and scatter produce scatter plots. The MATLAB function plotmatrix can produce a matrix of such plots showing the relationship between several pairs of variables.

What is a scatter plot with 3? ›

3D scatter plots are used to plot data points on three axes in the attempt to show the relationship between three variables. Each row in the data table is represented by a marker whose position depends on its values in the columns set on the X, Y, and Z axes.

How to create a 3D model in MATLAB? ›

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 draw a 3D scatter plot? ›

Create Chart

After adding data, go to the 'Traces' section under the 'Structure' menu on the left-hand side. Choose the 'Type' of trace, then choose '3D Scatter' under '3D' chart type. Next, select 'X', 'Y' and 'Z' values from the dropdown menus. This will create a 3D scatter trace, as seen below.

What is the size of the marker in a 3D scatter plot? ›

scatter3d(x,y,z) creates a scatter plot with markers at the locations specified by x , y , and z . The default type of the marker is a circle, the default color is "blue" and the default marker size is 36. This means the circle surrounding the marker has an area of 36 points squared.

How do you interpret a scatter plot example? ›

You interpret a scatterplot by looking for trends in the data as you go from left to right: If the data show an uphill pattern as you move from left to right, this indicates a positive relationship between X and Y. As the X-values increase (move right), the Y-values tend to increase (move up).

How to customize a scatter plot in Matlab? ›

One way to plot data from a table and customize the colors and marker sizes is to set the ColorVariable and SizeData properties. You can set these properties as name-value arguments when you call the scatter function, or you can set them on the Scatter object later.

How to group a scatter plot in Matlab? ›

gscatter( x , y , g ) creates a scatter plot of x and y , grouped by g . The inputs x and y are vectors of the same size. gscatter( x , y , g , clr , sym , siz ) specifies the marker color clr , symbol sym , and size siz for each group.

What are examples of scatter plot? ›

A simple scatter plot can be used to see the difference in outdoor temperatures compared to ice cream sales. The two variables would be outside temperature and ice cream sales. This data could be collected and organized into a table. Once the data is organized into a table, it can be turned into ordered pairs.

What can a scatter plot tell you? ›

A scatter plot identifies a possible relationship between changes observed in two different sets of variables. It provides a visual and statistical means to test the strength of a relationship between two variables.

What are the three main uses of scatter plot? ›

Scatter plots' primary uses are to observe and show relationships between two numeric variables. The dots in a scatter plot not only report the values of individual data points, but also patterns when the data are taken as a whole. Identification of correlational relationships are common with scatter plots.

How to plot 3-D radiation pattern in MATLAB? ›

Use the patternCustom function to plot the field data in 3-D. This function also allows you to view the sliced data. Alternatively, use the polarpattern object to visualize the field data in 2-D polar format.

How to plot a 3-D triangle in MATLAB? ›

trisurf( T , x , y , z ) plots the 3-D triangular surface defined by the points in vectors x , y , and z , and a triangle connectivity matrix T . trisurf( TO ) plots the surface defined by a 3-D triangulation or delaunayTriangulation object.

References

Top Articles
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 5863

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.