Matlab

How to Increase Marker Size in Scatter Plot in MATLAB

Plots are mostly used for presenting data in the fields of science and engineering. In MATLAB, you can use several functions to generate a plot of any type and can customize them according to your liking. Among those plots, scatter plots are widely used for discrete data visualization. In scatter plots, increasing the marker size is an important task to make the data points more visible and easier to distinguish.

If you are unfamiliar with increasing marker size in scatter plots, this blog will teach you how to perform this task in MATLAB.

What is the Scatter Plot and How to Generate it in MATLAB?

The scatter plots are used for discrete coordinate points visualization. These plots play a crucial role in statistics and data science to plot large data sets. In MATLAB, these plots are created using the built-in scatter() function, which by default uses the circular marker style for visualizing the data set.

Syntax

The scatter() function’s syntax is given below:

scatter(x,y)

scatter(x,y,sz)

Here,

The function scatter(x,y) yields a scatter plot having a circular markers style where x and y are specified vectors.

The function scatter(x,y,sz) yields to specify the marker size. If we declare sz as a scalar value, all the circles will have an equal size however, if we set the sz as a vector value then all the circles will have distinct sizes.

How to Increase Marker Size in Scatter Plots in MATLAB?

By default, the scatter() function in MATLAB uses the default marker size as 6, if we don’t specify the marker size argument. However, we can increase this marker size in scatter plots according to our needs by including the number of our choice.

Examples

Let’s consider some examples to understand how to increase marker size in a scatter plot in MATLAB.

Example 1: Increase Marker Size in Scatter Plot from 50 to 100

This example first graphs a scatter plot utilizing the scatter(x, y, sz) function by declaring the marker size sz = 50. After that, it again generates the same scatter plot by increasing its marker size sz=100.

x = linspace(-100*pi,100*pi);

y = sin(x) + rand(1,100);

nexttile

scatter(x,y,50)

nexttile

scatter(x,y,100)

Example 2: Increase Marker Size in Scatter Plot from 50 to 500

In this example first, we draw a scatter plot utilizing the function scatter(x, y, sz) by declaring the marker size sz = 50. After that, we again generate the same scatter plot by increasing its marker size to sz=500.

t = linspace(0,5,1000);

x = exp(t).*cos(500*t);

y = exp(t).*sin(500*t);

nexttile

scatter(x,y,50)

nexttile

scatter(x,y,500)

Conclusion

The scatter() is a beneficial function in MATLAB that is used for generating the scatter plots in MATLAB. By default, the function uses the marker size of 6 and generates circular size markers in MATLAB plots. However, we can easily increase the marker size inside the scatter() function by proving the value of our choice. This guide has covered the complete procedure of increasing the marker size in MATLAB.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.