# matlab pairplot **Repository Path**: slandarer/matlab-pairplot ## Basic Information - **Project Name**: matlab pairplot - **Description**: SPairplot Create and customize pairplot (scatter plot matrix | 散点图矩阵) - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-18 - **Last Updated**: 2026-06-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pairplot (scatter plot matrix | 散点图矩阵) SPairplot Create and customize pairplot (scatter plot matrix | 散点图矩阵) #### mathworks fileexchange 链接(引用格式) Zhaoxu Liu / slandarer (2026). pairplot (scatter plot matrix | 散点图矩阵) (https://www.mathworks.com/matlabcentral/fileexchange/184069-pairplot-scatter-plot-matrix), MATLAB Central File Exchange. Retrieved June 18, 2026. ## Cover ![](gallery/demo5_1.png) ## Basic usage : one matrix input ```matlab % Load Fisher's iris dataset (150 samples, 4 features, 3 species) % 加载鸢尾花数据集(150个样本,4个特征,3个品种) fisher = load("fisheriris.mat"); X = fisher.meas; % 150×4 feature matrix / 特征矩阵 group = fisher.species; % Species labels / 品种标签 label = {'sepal-length', 'sepal-width', 'petal-length', 'petal-width'}; % Create pairplot object with customized visualization % 创建散点图矩阵对象,自定义可视化风格 SP = SPairplot(X, 'Group', group, 'DiagType', 12, 'UpperType', 11, 'LowerType', 13); SP.draw(); % Set X-labels and Y-labels % 设置 X 轴标签和 Y 轴标签 SP.setXLabelString(label); SP.setYLabelString(label); ``` ![](gallery/demo1_12_11_13.png) ![](gallery/demo1_11_7_10.png) ![](gallery/demo1_6_9_6.png) ![](gallery/demo1_1_9_2.png) ## DiagType, BottomType and RightType ![](DiagType.png) ## UpperType and LowerType ![](LowerType.png) ## Basic usage : Two matrix inputs ```matlab % Generate synthetic data with three groups (150 samples, 6 features total) % 生成包含三个分组的合成数据(150个样本,共6个特征) P1 = mvnrnd([0,20,0,10,8,7], eye(6).*6, 50); P2 = mvnrnd([10,5,15,0,4,2], eye(6).*8, 50); P3 = mvnrnd([10,15,0,0,2,3], eye(6).*[3,9,2,1,4,4], 50); G = [ones(50,1)*1; ones(50,1)*2; ones(50,1)*3]; % Group labels / 分组标签 % Split into X (first 4 variables) and Y (last 2 variables) % 拆分为 X(前4个变量)和 Y(后2个变量) XY = [P1; P2; P3]; X = XY(:, 1:4); Y = XY(:, 5:6); % Create pairplot with two variable sets (X vs Y) % 创建双变量集的散点图矩阵(X 与 Y 的对比) % Note: When X and Y are both provided, only LowerType (off-diagonal below) % is effective. Upper triangle and diagonal are automatically disabled. % 注意:当同时输入 X 和 Y 时,仅 LowerType(下三角区域)生效, % 上三角和对角线区域自动禁用。 SP = SPairplot(X, Y, 'Group', G, 'LowerType', 9); SP.draw(); ``` ![](gallery/demo2.png) ## Properties setting for subplots ```matlab fisher = load("fisheriris.mat"); X = fisher.meas; group = fisher.species; label = {'sepal-length', 'sepal-width', 'petal-length', 'petal-width'}; SP = SPairplot(X, 'Group', group, 'DiagType', 1, 'UpperType', 9, 'LowerType', 2); % set CData SP.CData = [119,69,133; 56,108,155; 33,160,122] ./ 255; SP.draw(); % Set X-labels and Y-labels SP.setXLabelString(label); SP.setYLabelString(label); % Customize subplot appearance % 自定义子图外观 SP.setAxes('Box','off', 'LineWidth',1.5, 'XGrid','on', 'YGrid','on') SP.setXLabel('FontWeight','bold', 'Color',[0,0,.8]) SP.setYLabel('FontWeight','bold', 'Color',[.8,0,0]) ``` ![](gallery/demo3.png) ## Display legend ```matlab fisher = load("fisheriris.mat"); X = fisher.meas; group = fisher.species; label = {'sepal-length', 'sepal-width', 'petal-length', 'petal-width'}; SP = SPairplot(X, 'Group', group, 'DiagType', 10, 'UpperType', 9, 'LowerType', 2); % set CData SP.CData = [211, 43, 43; 61, 96,137; 249,206, 61; 76,103, 86; 80, 80, 80]./255; SP.Padding = [.08, .08, .2, .04]; SP.draw(); % Set X-labels and Y-labels SP.setXLabelString(label); SP.setYLabelString(label); legend(SP.axMat{4, 4}, SP.GroupLabel, 'FontSize',17, 'Position',[.82, .88, .12, .08]) ``` ![](gallery/demo4.png) ## Marginal plot : one matrix input ```matlab % Load Fisher's iris dataset (150 samples, 4 features, 3 species) % 加载鸢尾花数据集(150个样本,4个特征,3个品种) fisher = load("fisheriris.mat"); X = fisher.meas; % 150×4 feature matrix / 特征矩阵 group = fisher.species; % Species labels / 品种标签 label = {'sepal-length', 'sepal-width', 'petal-length', 'petal-width'}; % Create pairplot object with customized visualization % 创建散点图矩阵对象,自定义可视化风格 SP = SPairplot(X, 'Group', group); SP.DiagType = 14; SP.UpperType = 11; SP.LowerType = 14; SP.BottomType = 12; SP.RightType = 11; SP.CornerType = 1; SP.draw(); % Set X-labels and Y-labels % 设置 X 轴标签和 Y 轴标签 SP.setXLabelString(label); SP.setYLabelString(label); ``` ![](gallery/demo5_1.png) ![](gallery/demo5_2.png) ## Marginal plot : Two matrix inputs ```matlab % Generate synthetic data with three groups (150 samples, 6 features total) % 生成包含三个分组的合成数据(150个样本,共6个特征) P1 = mvnrnd([0,20,0,10,8,7], eye(6).*6, 50); P2 = mvnrnd([10,5,15,0,4,2], eye(6).*8, 50); P3 = mvnrnd([10,15,0,0,2,3], eye(6).*[3,9,2,1,4,4], 50); G = [ones(50,1)*1; ones(50,1)*2; ones(50,1)*3]; % Group labels / 分组标签 % Split into X (first 4 variables) and Y (last 2 variables) % 拆分为 X(前4个变量)和 Y(后2个变量) XY = [P1; P2; P3]; X = XY(:, 1:4); Y = XY(:, 5:6); % Create pairplot with two variable sets (X vs Y) % 创建双变量集的散点图矩阵(X 与 Y 的对比) % Note: When X and Y are both provided, only LowerType (off-diagonal below) % is effective. Upper triangle and diagonal are automatically disabled. % 注意:当同时输入 X 和 Y 时,仅 LowerType(下三角区域)生效, % 上三角和对角线区域自动禁用。 fig = figure('Units','normalized', 'Position',[.1,.2,.7,.65]); SP = SPairplot(fig, X, Y, 'Group', G); SP.GroupLabel = {'G1','G2','G3'}; SP.LowerType = 7; SP.BottomType = 12; SP.RightType = 14; SP.CornerType = 1; SP.draw(); SP.setXLabelString({'X1', 'X2', 'X3', 'X4'}); SP.setYLabelString({'Y1', 'Y2'}); ``` ![](gallery/demo6_1.png)