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)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 6175

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.