MATLAB 中的二維離散資料圖型別
MATLAB 是一種科學程式語言,提供了多種表達資訊的方式。其中之一是 **二維離散資料圖**。在 MATLAB 中,我們可以建立幾種不同型別的二維離散資料圖來以圖形方式表示資料和資訊。
在本文中,我們將探討 MATLAB 中不同型別的二維離散資料圖,並討論使用 MATLAB 程式設計實現它們的方法。因此,讓我們從 MATLAB 中二維離散資料圖的基本介紹開始。
二維離散資料圖簡介
在 MATLAB 中,二維離散資料圖是以圖形方式表示二維資訊或資料點的一種方法。它允許繪製 X 和 Y 軸之間資料的圖形。顧名思義,它提供了一種繪製由不同的單個數據點組成的離散資料的方法。離散資料圖沒有資料的連續圖形。
二維離散資料圖在資料視覺化和分析方面具有重要意義。這是因為,它們以圖形形式表示數值資料,並允許理解資料中存在的關聯和模式。因此,二維離散資料圖使資料分析和解釋更容易。
二維離散資料圖型別
下面列出了一些在 MATLAB 中常用的用於離散資料圖形表示的重要二維離散資料圖
**線圖** - 它是用於表示離散資料的最基本二維圖。它由一系列透過線段連線的資料點組成。
**散點圖** - 也稱為 X-Y 散點圖。散點圖是一種二維圖,它將單個數據點表示為標記。
**條形圖** - 條形圖使用不同高度或長度的垂直或水平矩形條來表示資料。這種型別的圖主要用於比較不同類別的數
**直方圖** - 直方圖是另一種在二維空間中表示離散資料的方式。直方圖用於透過將其劃分為一組箱來表示連續資料的分佈。每個箱表示落入其中的資料點的數量。直方圖被廣泛用於理解資料模式和資料分佈中的偏差。
**帕累託圖** - 它是二維離散圖的一種型別,使用垂直條表示資料集的值。在這種型別的圖中,條按從左到右的降序排列。除了條形之外,它還包含一條曲線,該曲線表示資料值從左到右移動時的累積貢獻。
**莖葉圖** - 在這種型別的圖中,資料使用帶有頂部氣泡的直線表示。在此圖表中,直資料線稱為莖,它從 x 軸開始併到達 y 軸上的資料值。莖葉圖是視覺化離散資料值的一種有效方法。
**階梯圖** - 這種型別的圖也稱為階梯圖。它是一種二維離散資料圖,用於將資料值表示為一系列連線的階梯,形成類似樓梯的結構。這種型別的圖主要用於視覺化資料的模式並分析突變。
**熱圖** - 它是另一種型別的二維離散資料圖。熱圖用於以二維單元格網格的形式表示資料值,其中每個單元格根據其對應的資料值填充顏色。在此圖中,單元格的顏色強度表示單元格的值。這種型別的圖在影像處理、相關矩陣、地理空間分析等領域都有應用。
因此,這就是關於 MATLAB 中不同型別的二維離散資料圖的全部內容。現在讓我們藉助示例程式瞭解如何使用 MATLAB 程式設計建立它們。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先將樣本資料定義為每月銷售額。然後,我們使用“plot”函式建立一個線形圖。此外,我們還應用了圖表標題和軸標籤,以提高圖表的可讀性。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們使用“scatter”函式建立了一個 x-y 散點圖。程式碼中的其餘部分與 MATLAB 程式 (1) 中的類似。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們使用“bar”函式建立了一個條形圖。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們使用“barh”函式建立了一個水平條形圖。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先建立一個年齡陣列。然後,我們建立其直方圖以顯示每個年齡的頻率,為此我們使用“histogram”函式。接下來,我們應用圖表標題和軸標籤,以提高圖表的可讀性。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先建立樣本資料“month”和“sale”。然後,我們使用“pareto”函式建立其帕累託圖。接下來,我們建立圖表標題和軸標籤,以提高圖表的可讀性。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先建立樣本資料“month”和“sale”。然後,我們使用“stem”函式建立其莖葉圖。然後,我們應用圖表標題和軸標籤,以提高圖表的可讀性。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先建立樣本資料“class”和“sale”。然後,我們使用“stairs”函式建立其階梯圖。然後,我們應用圖表標題和軸標籤,以提高圖表的可讀性。
示例
% 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');
輸出
解釋
在此 MATLAB 程式碼中,我們首先建立樣本資料“sale”作為表格。然後,我們使用“heatmap”函式建立其熱圖。然後,我們應用圖表標題和軸標籤,以提高圖表的可讀性。
結論
因此,這就是關於 MATLAB 中的二維離散資料圖及其型別的全部內容。MATLAB 提供了各種內建函式來建立不同型別的二維離散資料圖,以圖形方式表示資料點。在本文的上述部分中,我們藉助 MATLAB 程式討論了各種型別的二維離散資料圖。
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP