![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Types of 2-D Discrete Data Plots in MATLAB
MATLAB is a scientific programming language that provides different ways of expression information. One of them is 2D discrete data plots. In MATLAB, we can create several different types of 2D discrete data plots to represent data and information graphically.
In this article, we will explore different types of 2D discrete data plots in MATLAB, and will discuss their implementation using MATLAB programming. So, let’s start with the basic introduction of 2D discrete data plots in MATLAB.
Introduction to 2D Discrete Data Plot
In MATLAB, the 2D discrete data plot is a graphical way of representing information or data points in two dimensions. It allows to plot a graph of data between X and Y axes. As its name suggests, it provides a way to plot discrete data that consists of distinct individual data points. The discrete data plots do not have a continuous graph of data.
The 2D discrete data plots are significant in terms of visualization and analysis of data in an effective manner. This is because, they represent numeric data in graphical form and allows to understand the relationships and patterns present in the data. Therefore, the 2D discrete data plots make the analysis and interpretation of data easier.
Types of 2D Discrete Data Plots
Some important 2D discrete data plots commonly created in MATLAB for graphical representation of discrete data are listed below:
Line Plot − It is the most basic 2D plot used for representing discrete data. It consists of a series of data points connected through the line segments.
Scatter Plot − It is also known X−Y scatter plot. The scatter plot is a type of 2D plot that represents individual data points as markers.
Bar Plot − Bar plot represents data by using vertical or horizontal rectangular bars of different height or length. This type of plot is mainly used for comparing data of different categories.
Histogram Plot − The histogram is another way of representing discrete data in a two−dimensional space. The histogram is utilized to represent the distribution of continuous data by dividing it into a set of bins. Each bin represents the counting of number of data points that fall into it. Histogram is widely used to understand the data patterns and deviations in data distribution.
Pareto Plot − It is a type of 2D discrete chart utilizes vertical bars to represent the values of data sets. In this type of data plot, the bars are arranged in a descending order in a direction from left to right. In addition to the bars, this also consists of a curve line that represents the cumulative contribution of data values while moving from left to right.
Stem Plot − In this type of graph, the data is represented by using a straight line with a bubble at the top. In this chart, the straight data line is termed as a stem which starts from the x−axis and go to the data value on the y−axis. The step plot is an effective way of visualizing discrete data values.
Stairstep Plot − This type of plot is also known as step plot. It is a 2D discrete data plot used to represent data values as a series of connected steps, making a structure like a staircase. This type of plot is mainly used to visualize the pattern of the data and analyze the abrupt changes.
Heatmap Plot − It is another type of 2D discrete data plot. The heatmap is used to represent data values in the form of a 2D grid of cells, where each cell filled with a color based on its corresponding data value. In this graph, the color intensity of the cell represents the value of the cell. This type of plot finds applications in the field of image processing, correlation matrices, geospatial analysis, etc.
Hence, this is all about different types of 2D discrete data plots in MATLAB. Let us now understand their creation using MATLAB programming with the help of example programs.
Example
% MATLAB code for plotting 2D line graph % Create a sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the line chart plot(month, sale); % Create chart title and axis labels for better readability title('Line Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471105.jpg)
Explanation
In this MATLAB code, we start by defining sample data as sale per month. Then, we create a line graph by using the ‘plot’ function. Also, we applied chart title and axis labels for better readability of the graph.
Example
% MATLAB code for plotting 2D scatter graph % Create sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the x-y scatter chart scatter(month, sale); % Create chart title and axis labels for better readability title('Scatter Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471123.jpg)
Explanation
In this MATLAB code, we created an x−y scatter chart by using the ‘scatter’ function. The rest things in the code are similar to that in the MATLAB program (1).
Example
% MATLAB code for plotting 2D bar graph % Create sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the bar chart bar(month, sale); % Create chat title and axis labels for better readability title('Bar Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471131.jpg)
Explanation
In this MATLAB code, we created a bar chart by using the ‘bar’ function.
Example
% MATLAB code for plotting 2D horizontal bar graph % Create sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the horizontal bar chart barh(month, sale); % Create chat title and axis labels for better readability title('Horizontal Bar Plot'); xlabel('Sale'); ylabel('Month');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471156.jpg)
Explanation
In this MATLAB code, we created a horizontal bar chart by using the ‘barh’ function.
Example
% MATLAB code for plotting 2D histogram graph % Create sample data age = [15 20 15 17 25 35 25 35 17 15 15 13]; % Plot the histogram chart histogram(age); % Create chat title and axis labels for better readability title('Histogram Plot'); xlabel('age'); ylabel('Frequency');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471164.jpg)
Explanation
In this MATLAB code, we start by creating an array of ages. Then, we create its histogram plot to show the frequency of each age, for this we use the ‘histogram’ function. Next, we apply chart title and axis labels for better readability of the chart.
Example
% MATLAB code for plotting pareto chart % Create a sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the pareto chart pareto(month, sale); % Apply chart title and axis labels title('Pareto Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471236.jpg)
Explanation
In this MATLAB code, we start by creating a sample data ‘month’ and ‘sale’. Then, we create its pareto plot using the ‘pareto’ function. Next, we create chart title and axis labels for better readability of the plot.
Example
% MATLAB code for plotting stem chart % Create a sample data month = categorical({'Jan', 'Feb', 'Mar', 'Apr'}); sale = [15000, 20000, 30000, 25000]; % Plot the stem chart stem(month, sale); % Apply chart title and axis labels title('Stem Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471252.jpg)
Explanation
In this MATLAB code, we firstly create a sample data ‘month’ and ‘sale’. Then, we create its stem plot using the ‘stem’ function. Then, we apply chart title and axis labels for better readability of the plot.
Example
% MATLAB code for plotting stairstep chart % Create a sample data class = categorical({'A', 'B', 'C', 'D'}); sale = [15000, 20000, 30000, 25000]; % Plot the stairstep chart stairs(class, sale); % Apply chart title and axis labels title('Stairstep Plot'); xlabel('Class'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471265.jpg)
Explanation
In this MATLAB code, we firstly create a sample data ‘class’ and ‘sale’. Then, we create its stairstep plot using the ‘stairs’ function. Then, we apply chart title and axis labels for better readability of the plot.
Example
% MATLAB code for plotting heatmap chart % Create a sample data sale = [15000, 20000; 30000, 25000; 15000, 17000]; % Plot the heatmap chart heatmap(sale); % Apply chart title and axis labels title('Heatmap Plot'); xlabel('Month'); ylabel('Sale');
Output
![](https://www.tutorialspoint.com/assets/questions/media/334420-1691471279.jpg)
Explanation
In this MATLAB code, we firstly create a sample data ‘sale’ as a table. Then, we create its heatmap plot using the ‘heatmap’ function. Then, we apply chart title and axis labels for better readability of the plot.
Conclusion
Hence, this is all about 2D discrete data plots and their types in MATLAB. MATLAB provides various built−in functions to create different types of 2D discrete data plots for graphical representation of data points. In the above sections of this article, we have discussed various types of 2D discrete data plots with the help of MATLAB programs.