MATLAB | 全网最全边际图绘制模板(直方图、小提琴图、箱线图、雨云图、散点图... ...)

news2024/11/13 18:21:29

如标题所言,这应该是全网最全的边际图绘制模板,中心图有8种格式,边际图有11种格式,共计88种组合,另外模板中给了8款配色,我愿称其为888组合,只需要更换一下数据就能绘制出各种类型的边际图:

甚至可以随意拖动改变X,Y轴范围:


教程部分

以下代码展示顺序仅为讲解方便,实际顺序请见完整代码部分。

0 数据准备

就每组数据都是两列的数值矩阵,之后放在元胞数组中即可,如下例:

% 构造三个符合高斯分布的点集
PntSet1=mvnrnd([2 3],[1 0;0 2],300);
PntSet2=mvnrnd([6 7],[1 0;0 2],300);
PntSet3=mvnrnd([14 9],[1 0;0 1],300);
% 将数据放进元胞数组
PntSet={PntSet1,PntSet2,PntSet3};

1 坐标区域绘制

就简单的构造了三个坐标区域,X,Y轴标签啥的都可自行修改:

% figure图床及主要区域axes坐标区域创建及基础修饰
fig=figure('Units','normalized','Position',[.3,.2,.5,.63]);
axM=axes('Parent',fig);hold on;
set(axM,'Position',[.08,.08,.65,.65],'LineWidth',1.1,'Box','on','TickDir','in',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09)
axM.XLabel.String='Main XXXXX';
axM.YLabel.String='Main YYYYY';
axM.XLabel.FontSize=14;
axM.YLabel.FontSize=14;
% -------------------------------------------------------------------------
% 右侧axes坐标区域创建及基础修饰
axR=axes('Parent',fig);hold on;
set(axR,'Position',[.75,.08,.23,.65],'LineWidth',1.1,'Box','off','TickDir','out',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09,'TickLength',[.006 .015],'YTickLabel','')
axR.XLabel.String='Y-axis data statistics';
axR.XLabel.FontSize=14;
% -------------------------------------------------------------------------
% 上方axes坐标区域创建及基础修饰
axU=axes('Parent',fig);hold on;
set(axU,'Position',[.08,.76,.65,.2],'LineWidth',1.1,'Box','off','TickDir','out',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09,'TickLength',[.006 .015],'XTickLabel','')
axU.YLabel.String='X-axis data statistics';
axU.YLabel.FontSize=14;

2 配色

可以自行替换RGB三元组,同时本模板也贴心的提供了八款配色,只需修改:

  • colorList=Cn
    中n的数值即可:
% 配色预设(here to change the default color list)
C1=[211 43 43;61 96 137;249 206 61;76 103 86;80 80 80]./255;
C2=[102,173,194;36,59,66;232,69,69;194,148,102;54,43,33]./255;
C3=[223,122,94;60 64 91;130 178 154;244,241,222;240 201 134]./255;
C4=[122,117,119;255,163,25;135,146,73;126,15,4;30,93,134]./255;
C5=[198,199,201;38,74,96;209,80,51;241,174,44;12,13,15]./255;
C6=[235,75,55;77,186,216;58,84,141;2,162,136;245,155,122]./255;
C7=[23,23,23;121,17,36;31,80,91;44,9,75;61,36,42]./255;
C8=[47,62,66;203,129,70;0 64 115;152,58,58;20 72 83]./255;
colorList=C2;

以下是配色展示:

C1

C2

C3

C4

C5

C6

C7

C8

3 绘图格式修改

中心图及边缘图格式可以通过修改:

  • mainType
  • marginType

俩参数进行修改,mainType为中心图类型,可选1-8,marginType为边际图类型,可选1-11,

% 在这改边缘图及中心图种类
% (here to change the type of marginal plot and main plot)
%    |
%    |
%    |
% \  |  /
%  \ | /
%   \|/
%     
mainType=5;
marginType=7;
%  
%   /|\
%  / | \
% /  |  \
%    |
%    |
%    |

4 中心图

中心图绘制代码:

% 主要区域散点图绘制
switch mainType
    case 1 % 散点图
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            scatter(axM,tPntSet(:,1),tPntSet(:,2),70,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.6)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
    case 2 % 等高线图
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            gridx1=linspace(min(tPntSet(:,1)),max(tPntSet(:,1)),round(sqrt(size(tPntSet,1))));
            gridx2=linspace(min(tPntSet(:,2)),max(tPntSet(:,2)),round(sqrt(size(tPntSet,1))));
            [x1,x2]=meshgrid(gridx1, gridx2);
            [m,n]=size(x1);
            x1=x1(:);
            x2=x2(:);
            xi=[x1,x2];
            h=ksdensity(tPntSet,xi);
            contour(axM,reshape(x1,[m,n]),reshape(x2,[m,n]),reshape(h,[m,n]),...
                'LineWidth',1.2,'EdgeColor',colorList(i,:))
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
    case 3 % 回归曲线
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            [p,S]=polyfit(tPntSet(:,1),tPntSet(:,2),1); 
            x1=linspace(min(tPntSet(:,1)),max(tPntSet(:,1)),100);
            [y_fit,delta]=polyval(p,x1,S);
            % 绘制原始数据、线性拟合和 95% 预测区间 y±2Δ。
            uy=y_fit+2.*delta;
            dy=y_fit-2.*delta;
            % 绘制原始数据
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            % 绘制拟合曲线
            plot(axM,x1,y_fit,'Color',colorList(i,:),'LineWidth',2.5)
            % 绘制置信区间
            fill(axM,[x1,x1(end:-1:1)],[uy,dy(end:-1:1)],colorList(i,:),'EdgeColor','none','FaceAlpha',.15)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 4 % 散点+凸包
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            [k,av]=convhull(tPntSet);
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            fill(axM,tPntSet(k,1),tPntSet(k,2),colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 5 % 散点+不规则图形
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            R=max(max(tPntSet(:,1))-min(tPntSet(:,1)),max(tPntSet(:,2))-min(tPntSet(:,2)))./round(sqrt(size(tPntSet,1)));
            t=linspace(0,2*pi,100);
            [k,~]=convhull(tPntSet);
            kPntSet=tPntSet(k,:);
            kX=repmat(kPntSet(:,1),[1,100])+repmat(cos(t).*R,[length(k),1]);
            kY=repmat(kPntSet(:,2),[1,100])+repmat(sin(t).*R,[length(k),1]);
            kX=kX(:);kY=kY(:);
            [k,av]=convhull([kX,kY]);
            fill(axM,kX(k),kY(k),colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 6 % 椭圆形
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            Mu=mean(tPntSet);
            Y=tPntSet-repmat(Mu,size(tPntSet,1),1);
            Sigma=(Y'*(ones(size(tPntSet,1),1).*Y))./size(tPntSet,1);
            [X,Y]=getEllipse(Mu,Sigma,9.21,100);
            fill(axM,X,Y,colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 7 % 簇状
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            Mu=mean(tPntSet);
            LX=[tPntSet(:,1),Mu(1).*ones(size(tPntSet,1),1),nan(size(tPntSet,1),1)]';
            LY=[tPntSet(:,2),Mu(2).*ones(size(tPntSet,1),1),nan(size(tPntSet,1),1)]';
            plot(axM,LX(:),LY(:),'Color',colorList(i,:),'LineWidth',1.2);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 8 % 误差棒
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            Mu=mean(tPntSet);
            SX=std(tPntSet(:,1));
            SY=std(tPntSet(:,2));
            errorbar(axM,Mu(1),Mu(2),SY,SY,SX,SX,'o','LineWidth',1.5,'Color',colorList(i,:),'MarkerSize',10);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
end

中心图格式展示:

1 散点图

2 等高线图

3 回归曲线

由于数据不是很线形,因此置信区间比较大:

4 多边形边界

5 不规则图形边界

6 椭圆置信区间

7 与质心连线

点少点更好看:

8 误差棒

5 边际图

边际图绘制代码:

% 边际图绘制
axR.YLim=axM.YLim;
axU.XLim=axM.XLim;
for i=1:length(PntSet)
tPntSet=PntSet{i};
switch marginType
    case 1 % 柱状图
        histogram(axR,tPntSet(:,2),'FaceColor',colorList(i,:),'Orientation','horizontal',...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8)
        histogram(axU,tPntSet(:,1),'FaceColor',colorList(i,:),...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8)
    case 2 % 核密度面
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0],[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none')
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none')
    case 3 % 核密度线
        [f,yi]=ksdensity(tPntSet(:,2));
        plot(axR,f,yi,'Color',colorList(i,:),'LineWidth',2)
        [f,xi]=ksdensity(tPntSet(:,1));
        plot(axU,xi,f,'Color',colorList(i,:),'LineWidth',2)
    case 4 % 核密度面+线
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0],[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axR,f,yi,'Color',colorList(i,:),'LineWidth',1.2)
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axU,xi,f,'Color',colorList(i,:),'LineWidth',1.2)
    case 5 % 直方图+密度线
        HR=histogram(axR,tPntSet(:,2),'FaceColor',colorList(i,:),'Orientation','horizontal',...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8);
        HU=histogram(axU,tPntSet(:,1),'FaceColor',colorList(i,:),...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8);
        [f,yi]=ksdensity(tPntSet(:,2));
        plot(axR,f.*size(tPntSet,1).*HR.BinWidth,yi,'Color',colorList(i,:),'LineWidth',2)
        [f,xi]=ksdensity(tPntSet(:,1));
        plot(axU,xi,f.*size(tPntSet,1).*HU.BinWidth,'Color',colorList(i,:),'LineWidth',2)
    case 6 % 箱线图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i],[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i],[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.15,.15]+i,[max(tjDataY),max(tjDataY)],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.15,.15]+i,[min(tjDataY),min(tjDataY)],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.25,.25]+i,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        fill(axR,i+.25.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[max(tjDataX),max(tjDataX)],[-.15,.15]+i,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),min(tjDataX)],[-.15,.15]+i,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[med,med],[-.25,.25]+i,'LineWidth',1.2,'Color',colorList(i,:))
        fill(axU,[qt25,qt25,qt75,qt75],i+.25.*1.*[-1 1 1 -1],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        axU.YLim=[0,length(PntSet)+1];
    case 7 % 小提琴图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[f,-f(end:-1:1)].*1.2+i,[yi,yi(end:-1:1)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i],[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i],[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi,xi(end:-1:1)],[f,-f(end:-1:1)].*1.2+i,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
    case 8 % 线条散点
        LY=[tPntSet(:,2),tPntSet(:,2),tPntSet(:,2).*nan]';
        LX=repmat([i-.3,i+.3,nan],[size(tPntSet,1),1])';
        line(axR,LX(:),LY(:),'Color',[colorList(i,:),.4],'lineWidth',1)
        axR.XLim=[0,length(PntSet)+1];
        LX=[tPntSet(:,1),tPntSet(:,1),tPntSet(:,1).*nan]';
        LY=repmat([i-.3,i+.3,nan],[size(tPntSet,1),1])';
        line(axU,LX(:),LY(:),'Color',[colorList(i,:),.4],'lineWidth',1)
        axU.YLim=[0,length(PntSet)+1];
    case 9 % 山脊图
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0]+(i-1).*.5,[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axR,f+(i-1).*.5,yi,'Color',colorList(i,:),'LineWidth',1.2)
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0]+(i-1).*.5,colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axU,xi,f+(i-1).*.5,'Color',colorList(i,:),'LineWidth',1.2)
    case 10 % 类小提琴图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[0,f,0].*1.2+i+.15,[yi(1),yi,yi(end)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i-.15,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i]-.2,[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i]-.2,[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i-.2+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i-.2,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi(1),xi,xi(end)],[0,f,0].*1.2+i+.15,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i-.2,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i-.2+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i-.2,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
    case 11 % 雨云图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[0,f,0].*1.2+i+.15,[yi(1),yi,yi(end)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        scatter(axR,tPntSet(:,2).*0+i-.2+.22.*(rand(size(tPntSet,1),1)-.5).*2,tPntSet(:,2),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.3)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i]-.2,[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i]-.2,[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i-.2+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i-.2,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi(1),xi,xi(end)],[0,f,0].*1.2+i+.15,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        scatter(axU,tPntSet(:,1),tPntSet(:,1).*0+i-.2+.22.*(rand(size(tPntSet,1),1)-.5),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.3)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i-.2+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i-.2,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
end
end
linkaxes([axM,axR],'y')
linkaxes([axM,axU],'x')
%% ========================================================================
% 所使用到的函数
% 置信椭圆定位函数
function [X,Y]=getEllipse(Mu,Sigma,S,pntNum)
% 置信区间 | 95%:5.991  99%:9.21  90%:4.605
% (X-Mu)*inv(Sigma)*(X-Mu)=S

invSig=inv(Sigma);

[V,D]=eig(invSig);
aa=sqrt(S/D(1));
bb=sqrt(S/D(4));

t=linspace(0,2*pi,pntNum);
XY=V*[aa*cos(t);bb*sin(t)];
X=(XY(1,:)+Mu(1))';
Y=(XY(2,:)+Mu(2))';
end

边际图格式展示:

1 直方图

2 核密度填充

3 核密度线

4 核密度线+填充

5 直方图+密度线

6 箱线图

7 小提琴图

8 散点图

9 山脊图

10 类小提琴图

11 雨云图


完整代码

% 边际图示例
% marginalPlotDemo
% @author : slandarer
% Zhaoxu Liu / slandarer (2023). marginal plot 
% (https://www.mathworks.com/matlabcentral/fileexchange/123470-marginal-plot), 
% MATLAB Central File Exchange. 检索来源 2023/1/19.


% 构造三个符合高斯分布的点集
PntSet1=mvnrnd([2 3],[1 0;0 2],300);
PntSet2=mvnrnd([6 7],[1 0;0 2],300);
PntSet3=mvnrnd([14 9],[1 0;0 1],300);
% 将数据放进元胞数组
PntSet={PntSet1,PntSet2,PntSet3};
% -------------------------------------------------------------------------
% 配色预设(here to change the default color list)
C1=[211 43 43;61 96 137;249 206 61;76 103 86;80 80 80]./255;
C2=[102,173,194;36,59,66;232,69,69;194,148,102;54,43,33]./255;
C3=[223,122,94;60 64 91;130 178 154;244,241,222;240 201 134]./255;
C4=[122,117,119;255,163,25;135,146,73;126,15,4;30,93,134]./255;
C5=[198,199,201;38,74,96;209,80,51;241,174,44;12,13,15]./255;
C6=[235,75,55;77,186,216;58,84,141;2,162,136;245,155,122]./255;
C7=[23,23,23;121,17,36;31,80,91;44,9,75;61,36,42]./255;
C8=[47,62,66;203,129,70;0 64 115;152,58,58;20 72 83]./255;
colorList=C2;
% -------------------------------------------------------------------------
% 在这改边缘图及中心图种类
% (here to change the type of marginal plot and main plot)
%    |
%    |
%    |
% \  |  /
%  \ | /
%   \|/
%     
mainType=1;
marginType=1;
%  
%   /|\
%  / | \
% /  |  \
%    |
%    |
%    |
%% =========================================================================
% figure图床及主要区域axes坐标区域创建及基础修饰
fig=figure('Units','normalized','Position',[.3,.2,.5,.63]);
axM=axes('Parent',fig);hold on;
set(axM,'Position',[.08,.08,.65,.65],'LineWidth',1.1,'Box','on','TickDir','in',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09)
axM.XLabel.String='Main XXXXX';
axM.YLabel.String='Main YYYYY';
axM.XLabel.FontSize=14;
axM.YLabel.FontSize=14;
% -------------------------------------------------------------------------
% 右侧axes坐标区域创建及基础修饰
axR=axes('Parent',fig);hold on;
set(axR,'Position',[.75,.08,.23,.65],'LineWidth',1.1,'Box','off','TickDir','out',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09,'TickLength',[.006 .015],'YTickLabel','')
axR.XLabel.String='Y-axis data statistics';
axR.XLabel.FontSize=14;
% -------------------------------------------------------------------------
% 上方axes坐标区域创建及基础修饰
axU=axes('Parent',fig);hold on;
set(axU,'Position',[.08,.76,.65,.2],'LineWidth',1.1,'Box','off','TickDir','out',...
    'XMinorTick','on','YMinorTick','on','XGrid','on','YGrid','on','GridLineStyle','--',...
    'FontName','Times New Roman','FontSize',12,'GridAlpha',.09,'TickLength',[.006 .015],'XTickLabel','')
axU.YLabel.String='X-axis data statistics';
axU.YLabel.FontSize=14;
%% =========================================================================
% 主要区域散点图绘制
switch mainType
    case 1 % 散点图
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            scatter(axM,tPntSet(:,1),tPntSet(:,2),70,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.6)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
    case 2 % 等高线图
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            gridx1=linspace(min(tPntSet(:,1)),max(tPntSet(:,1)),round(sqrt(size(tPntSet,1))));
            gridx2=linspace(min(tPntSet(:,2)),max(tPntSet(:,2)),round(sqrt(size(tPntSet,1))));
            [x1,x2]=meshgrid(gridx1, gridx2);
            [m,n]=size(x1);
            x1=x1(:);
            x2=x2(:);
            xi=[x1,x2];
            h=ksdensity(tPntSet,xi);
            contour(axM,reshape(x1,[m,n]),reshape(x2,[m,n]),reshape(h,[m,n]),...
                'LineWidth',1.2,'EdgeColor',colorList(i,:))
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
    case 3 % 回归曲线
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            [p,S]=polyfit(tPntSet(:,1),tPntSet(:,2),1); 
            x1=linspace(min(tPntSet(:,1)),max(tPntSet(:,1)),100);
            [y_fit,delta]=polyval(p,x1,S);
            % 绘制原始数据、线性拟合和 95% 预测区间 y±2Δ。
            uy=y_fit+2.*delta;
            dy=y_fit-2.*delta;
            % 绘制原始数据
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            % 绘制拟合曲线
            plot(axM,x1,y_fit,'Color',colorList(i,:),'LineWidth',2.5)
            % 绘制置信区间
            fill(axM,[x1,x1(end:-1:1)],[uy,dy(end:-1:1)],colorList(i,:),'EdgeColor','none','FaceAlpha',.15)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 4 % 散点+凸包
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            [k,av]=convhull(tPntSet);
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            fill(axM,tPntSet(k,1),tPntSet(k,2),colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 5 % 散点+不规则图形
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            R=max(max(tPntSet(:,1))-min(tPntSet(:,1)),max(tPntSet(:,2))-min(tPntSet(:,2)))./round(sqrt(size(tPntSet,1)));
            t=linspace(0,2*pi,100);
            [k,~]=convhull(tPntSet);
            kPntSet=tPntSet(k,:);
            kX=repmat(kPntSet(:,1),[1,100])+repmat(cos(t).*R,[length(k),1]);
            kY=repmat(kPntSet(:,2),[1,100])+repmat(sin(t).*R,[length(k),1]);
            kX=kX(:);kY=kY(:);
            [k,av]=convhull([kX,kY]);
            fill(axM,kX(k),kY(k),colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2)
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 6 % 椭圆形
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            Mu=mean(tPntSet);
            Y=tPntSet-repmat(Mu,size(tPntSet,1),1);
            Sigma=(Y'*(ones(size(tPntSet,1),1).*Y))./size(tPntSet,1);
            [X,Y]=getEllipse(Mu,Sigma,9.21,100);
            fill(axM,X,Y,colorList(i,:),'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',2);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 7 % 簇状
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            sHdl(i)=scatter(axM,tPntSet(:,1),tPntSet(:,2),30,'filled','CData',colorList(i,:),'MarkerFaceAlpha',.9);
            Mu=mean(tPntSet);
            LX=[tPntSet(:,1),Mu(1).*ones(size(tPntSet,1),1),nan(size(tPntSet,1),1)]';
            LY=[tPntSet(:,2),Mu(2).*ones(size(tPntSet,1),1),nan(size(tPntSet,1),1)]';
            plot(axM,LX(:),LY(:),'Color',colorList(i,:),'LineWidth',1.2);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,sHdl,legendStr,'FontSize',14,'Box','off','Location','best');
    case 8 % 误差棒
        for i=1:length(PntSet)
            tPntSet=PntSet{i};
            Mu=mean(tPntSet);
            SX=std(tPntSet(:,1));
            SY=std(tPntSet(:,2));
            errorbar(axM,Mu(1),Mu(2),SY,SY,SX,SX,'o','LineWidth',1.5,'Color',colorList(i,:),'MarkerSize',10);
        end
        legendStr{length(PntSet)}='';
        for i=1:length(PntSet)
            legendStr{i}=['Class-',num2str(i)];
        end
        legend(axM,legendStr,'FontSize',14,'Box','off','Location','best');
end
% -------------------------------------------------------------------------
% 边际图绘制
axR.YLim=axM.YLim;
axU.XLim=axM.XLim;
for i=1:length(PntSet)
tPntSet=PntSet{i};
switch marginType
    case 1 % 柱状图
        histogram(axR,tPntSet(:,2),'FaceColor',colorList(i,:),'Orientation','horizontal',...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8)
        histogram(axU,tPntSet(:,1),'FaceColor',colorList(i,:),...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8)
    case 2 % 核密度面
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0],[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none')
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none')
    case 3 % 核密度线
        [f,yi]=ksdensity(tPntSet(:,2));
        plot(axR,f,yi,'Color',colorList(i,:),'LineWidth',2)
        [f,xi]=ksdensity(tPntSet(:,1));
        plot(axU,xi,f,'Color',colorList(i,:),'LineWidth',2)
    case 4 % 核密度面+线
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0],[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axR,f,yi,'Color',colorList(i,:),'LineWidth',1.2)
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axU,xi,f,'Color',colorList(i,:),'LineWidth',1.2)
    case 5 % 直方图+密度线
        HR=histogram(axR,tPntSet(:,2),'FaceColor',colorList(i,:),'Orientation','horizontal',...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8);
        HU=histogram(axU,tPntSet(:,1),'FaceColor',colorList(i,:),...
            'EdgeColor',[1 1 1]*.1,'FaceAlpha',0.6,'LineWidth',.8);
        [f,yi]=ksdensity(tPntSet(:,2));
        plot(axR,f.*size(tPntSet,1).*HR.BinWidth,yi,'Color',colorList(i,:),'LineWidth',2)
        [f,xi]=ksdensity(tPntSet(:,1));
        plot(axU,xi,f.*size(tPntSet,1).*HU.BinWidth,'Color',colorList(i,:),'LineWidth',2)
    case 6 % 箱线图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i],[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i],[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.15,.15]+i,[max(tjDataY),max(tjDataY)],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.15,.15]+i,[min(tjDataY),min(tjDataY)],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[-.25,.25]+i,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        fill(axR,i+.25.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[max(tjDataX),max(tjDataX)],[-.15,.15]+i,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),min(tjDataX)],[-.15,.15]+i,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[med,med],[-.25,.25]+i,'LineWidth',1.2,'Color',colorList(i,:))
        fill(axU,[qt25,qt25,qt75,qt75],i+.25.*1.*[-1 1 1 -1],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        axU.YLim=[0,length(PntSet)+1];
    case 7 % 小提琴图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[f,-f(end:-1:1)].*1.2+i,[yi,yi(end:-1:1)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i],[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i],[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi,xi(end:-1:1)],[f,-f(end:-1:1)].*1.2+i,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i],'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
    case 8 % 线条散点
        LY=[tPntSet(:,2),tPntSet(:,2),tPntSet(:,2).*nan]';
        LX=repmat([i-.3,i+.3,nan],[size(tPntSet,1),1])';
        line(axR,LX(:),LY(:),'Color',[colorList(i,:),.4],'lineWidth',1)
        axR.XLim=[0,length(PntSet)+1];
        LX=[tPntSet(:,1),tPntSet(:,1),tPntSet(:,1).*nan]';
        LY=repmat([i-.3,i+.3,nan],[size(tPntSet,1),1])';
        line(axU,LX(:),LY(:),'Color',[colorList(i,:),.4],'lineWidth',1)
        axU.YLim=[0,length(PntSet)+1];
    case 9 % 山脊图
        [f,yi]=ksdensity(tPntSet(:,2));
        fill(axR,[f,0]+(i-1).*.5,[yi,yi(1)],colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axR,f+(i-1).*.5,yi,'Color',colorList(i,:),'LineWidth',1.2)
        [f,xi]=ksdensity(tPntSet(:,1));
        fill(axU,[xi,xi(1)],[f,0]+(i-1).*.5,colorList(i,:),...
            'FaceAlpha',0.3,'EdgeColor','none');
        plot(axU,xi,f+(i-1).*.5,'Color',colorList(i,:),'LineWidth',1.2)
    case 10 % 类小提琴图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[0,f,0].*1.2+i+.15,[yi(1),yi,yi(end)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataY,'quartiles');
        outli=tjDataY(outliBool);
        scatter(axR,repmat(i-.15,[sum(outliBool),1]),outli,45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i]-.2,[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i]-.2,[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i-.2+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i-.2,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi(1),xi,xi(end)],[0,f,0].*1.2+i+.15,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        outliBool=isoutlier(tjDataX,'quartiles');
        outli=tjDataX(outliBool);
        scatter(axU,outli,repmat(i-.2,[sum(outliBool),1]),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.8)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i-.2+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i-.2,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
    case 11 % 雨云图
        tjDataY=tPntSet(:,2);fullDataY=tjDataY;
        [f,yi]=ksdensity(tjDataY);
        f(yi>max(tjDataY))=[];yi(yi>max(tjDataY))=[];
        f(yi<min(tjDataY))=[];yi(yi<min(tjDataY))=[];
        fill(axR,[0,f,0].*1.2+i+.15,[yi(1),yi,yi(end)],colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        scatter(axR,tPntSet(:,2).*0+i-.2+.22.*(rand(size(tPntSet,1),1)-.5).*2,tPntSet(:,2),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.3)
        tjDataY(outliBool)=[];
        qt25=quantile(fullDataY,0.25);
        qt75=quantile(fullDataY,0.75);
        med=median(fullDataY);
        plot(axR,[i,i]-.2,[max(tjDataY),qt75],'LineWidth',1.2,'Color',[0,0,0])
        plot(axR,[i,i]-.2,[min(tjDataY),qt25],'LineWidth',1.2,'Color',[0,0,0])
        fill(axR,i-.2+.2.*1.*[-1 1 1 -1],[qt25,qt25,qt75,qt75],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axR,[-.2,.2]+i-.2,[med,med],'LineWidth',1.2,'Color',colorList(i,:))
        axR.XLim=[0,length(PntSet)+1];
        % -----------------------------------------------------------------
        tjDataX=tPntSet(:,1);fullDataX=tjDataX;
        [f,xi]=ksdensity(tjDataX);
        f(xi>max(tjDataX))=[];xi(xi>max(tjDataX))=[];
        f(xi<min(tjDataX))=[];xi(xi<min(tjDataX))=[];
        fill(axU,[xi(1),xi,xi(end)],[0,f,0].*1.2+i+.15,colorList(i,:),'FaceAlpha',0.3,...
            'EdgeColor',colorList(i,:),'LineWidth',1.2);
        scatter(axU,tPntSet(:,1),tPntSet(:,1).*0+i-.2+.22.*(rand(size(tPntSet,1),1)-.5),45,'filled',...
            'CData',colorList(i,:),'LineWidth',1.2,'MarkerFaceAlpha',0.3)
        tjDataX(outliBool)=[];
        qt25=quantile(fullDataX,0.25);
        qt75=quantile(fullDataX,0.75);
        med=median(fullDataX);
        plot(axU,[max(tjDataX),qt75],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        plot(axU,[min(tjDataX),qt25],[i,i]-.2,'LineWidth',1.2,'Color',[0,0,0])
        fill(axU,[qt25,qt25,qt75,qt75],i-.2+.25.*1.*[-1 1 1 -1],[1,1,1],...
            'FaceAlpha',0.95,'EdgeColor',colorList(i,:),'LineWidth',1.2);
        plot(axU,[med,med],[-.25,.25]+i-.2,'LineWidth',1.2,'Color',colorList(i,:))
        axU.YLim=[0,length(PntSet)+1];
end
end
linkaxes([axM,axR],'y')
linkaxes([axM,axU],'x')
%% ========================================================================
% 所使用到的函数
% 置信椭圆定位函数
function [X,Y]=getEllipse(Mu,Sigma,S,pntNum)
% 置信区间 | 95%:5.991  99%:9.21  90%:4.605
% (X-Mu)*inv(Sigma)*(X-Mu)=S

invSig=inv(Sigma);

[V,D]=eig(invSig);
aa=sqrt(S/D(1));
bb=sqrt(S/D(4));

t=linspace(0,2*pi,pntNum);
XY=V*[aa*cos(t);bb*sin(t)];
X=(XY(1,:)+Mu(1))';
Y=(XY(2,:)+Mu(2))';
end
% Zhaoxu Liu / slandarer (2023). marginal plot 
% (https://www.mathworks.com/matlabcentral/fileexchange/123470-marginal-plot), 
% MATLAB Central File Exchange. 检索来源 2023/1/19.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/172113.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

中国机器视觉市场研究报告

目录 机器视觉行业概述机器视觉行业发展现状机器视觉行业典型企业分析机器视觉行业未来发展趋势 机器视觉行业概述 机器视觉定义 机器视觉&#xff08;Machine Vision&#xff0c;MV&#xff09;是人工智能正在快速发展的一个分支。根据美国制造工程师协会&#xff08;SME&…

数字孪生虚拟电厂负荷控制系统可视化

随着国家“双碳”及“构建以新能源为主体的新型电力系统”等目标的提出&#xff0c;清洁化、数字化越来越成为电力系统面临的迫切需求&#xff0c;负控系统的发展对电力营销现代化建设具有重要的意义。负控管理系统是一个着眼于全面加强电力信息管理的&#xff0c;集负荷控制、…

Tips for Confluence Administrators: Part 2

Part 1中&#xff0c;我们谈到了 Confluence 自定义配置的案例&#xff0c;例如&#xff1a;如何禁用附件下载&#xff1f;如何将iFrame放入Confluence&#xff1f;如何使我的页面完全私有&#xff1f;如何防止空间管理员删除他们的空间&#xff1f;任何软件都有bug&#xff0c…

Minecraft 1.19.2 Forge模组开发 11.Mixin

我们本次使用Mixin在1.19.2中制作一个属于自己的不死图腾。 演示效果演示效果演示效果 什么是Mixin&#xff1f; 简单来说是通过注入一些我们的代码&#xff0c;达到对MC原版内容的修改。 详细内容可以参考Minecraft 17.1 Mixin 1.首先我们需要在开发包中引入mixin的依赖&a…

深度学习——双向循环神经网络(笔记)

双向循环神经网络&#xff1a; ①对于序列来讲&#xff0c;假设的目标是&#xff1a;给定观测的情况下&#xff08;在时间序列的上下文或语言模型的上下文&#xff09;&#xff0c;对于下一个输出进行建模 ②对于序列模型来讲&#xff0c;可以从前往后看&#xff0c;也可以从…

Servlet基础

Servlet1. Servlet概述2. 快速入门3. 执行原理4. 生命周期方法5. Servlet3.06. 体系结构7. 相关配置8. HTTP8.1 概念8.2 Request8.3 Response8.4 ServletContext综合案例:文件下载&#xff1a;1. Servlet概述 Servlet是JavaEE规范(接口)之一Servlet是JavaWeb三大组件之一&…

使用sdk-npi-enablement-tool生成SVD文件和芯片头文件

使用sdk-npi-enablement-tool生成SVD文件和芯片头文件 文章目录使用sdk-npi-enablement-tool生成SVD文件和芯片头文件IntroductionOverviewOperation Steps创建芯片配置文件yaml填充外设模块的寄存器映射描述文件xlsx验证生成芯片头文件ConclusionIntroduction 芯片验证与测试…

【Linux杂篇】Linux系统终端常用配置文件更改

目录列表&#xff1a; 1.alias别名永久保存 2.解决vim文件没有颜色的问题 3.vim插件supertap插件安装&#xff08;可支持自动补全&#xff0c;非函数代码补全&#xff0c;仅支持在当前编辑文档内补全&#xff09; 4.vim插件管理 5.YCM下载 6.解决vim中使用backspace无法删…

windows安装npm和cnpm

npm: 代码的包管理器&#xff0c;但是服服器在国外&#xff0c;每一次启动项目都要下载一些依赖&#xff0c;耗时之久&#xff0c;官网下载链接戳 npm。 cnpm&#xff1a;这是淘宝团队出的npm的镜像&#xff0c;可用此代替官方的只读版本&#xff0c;官网链接 cnpm。 先安装np…

Redis6学习笔记【part3】配置文件与订阅/发布

一.Redis配置文件 1.Units单位 配置大小单位,开头定义了一些基本的度量单位&#xff0c;只支持bytes&#xff0c;不支持bit。其中 GB、Gb 大小写不敏感。 2.Include包含 类似 jsp 中的 include 引入公共页面 &#xff0c;redis 在多实例的情况也可以把公用的配置文件提取出来…

9 大指标分析 Solana 的熊市危机

Daniel, 2023 年 1 月Solana 是一个去中心化的区块链网络&#xff0c;由 Solana 实验室设计并在2020年推出&#xff0c;具有快速、可扩展和安全的特点。由于其快速的交易速度和低交易费用&#xff0c;Solana 在 2020 年和 2021 年获得了极大的关注&#xff0c;这使得它对去中心…

远程仓库操作

添加远程仓库 新建一个文件夹&#xff1a; 文件夹右键打开git bash: 初始化为git仓库&#xff1a; 在码云上新建一个git仓库&#xff1a; 复制链接&#xff1a; 在文件夹里使用git bash&#xff1a; git remote add<shortname><url> 添加一个新的远程仓库&…

制作tomcat的docker镜像

环境信息&#xff1a;MacBook Pro&#xff08;M1&#xff09;VMware-fusion(Player 版本 13.0.0 (20802013))Ubuntu 22.10tomcat镜像&#xff1a;centos-7.9.2009jdk1.8.0_341 apache-tomcat-8.5.84制作步骤&#xff1a;&#xff08;1&#xff09;下载好tomcat/jdk(我是在macbo…

学习react

这里写自定义目录标题学习React学习React 安装react的脚手架 npm i create-react-app -g通过脚手架创建demo D:\dev_project>create-react-app react-demo You are running Node 11.1.0. Create React App requires Node 14 or higher. Please update your version of No…

找不到合适好用的redis客户端工具?试试官方的客户端工具RedisInsight

这里是weihubeats,觉得文章不错可以关注公众号小奏技术&#xff0c;文章首发。拒绝营销号&#xff0c;拒绝标题党 背景 之前使用的redis客户端工具是AnotherRedisDesktopManager AnotherRedisDesktopManager github地址: https://github.com/qishibo/AnotherRedisDesktopManag…

千锋JavaScript学习笔记

千锋JavaScript学习笔记 文章目录千锋JavaScript学习笔记写在前面1. JS基础1.1 变量1.2 数据类型1.3 数据类型转换1.4 运算符1.5 条件1.6 循环1.7 函数1.8 对象数据类型1.9 数组和排序1.10 数组常用方法&#xff1a;1.11 字符串常用方法1.12 数字常用方法1.13 时间常用方法1.14…

九龙证券|三元锂离子电池和磷酸铁锂离子电池的特点和优劣势详解

动力蓄电池包括锂离子动力蓄电池、金属氢化物/镍动力蓄电池等。锂离子动力蓄电池一般简称为锂离子电池&#xff0c;锂离子电池是新能源轿车动力锂电池的重要品类&#xff0c;商场占有量也是最大的。新能源轿车商场上&#xff0c;锂离子电池常见的是磷酸铁锂离子电池和三元锂离子…

《图解HTTP》读书笔记

第一章、了解Web及网络基础 HTTP&#xff1a;HyperText Transfer Protocol&#xff0c;超文本传输协议。 HTML&#xff1a;HyperText Markup Language&#xff0c;超文本标记语言。 URL&#xff1a;Uniform Resource Locator&#xff0c;统一资源定位符。 把与互联网相关联的…

SQL题面试题

有3个表S(学生表)&#xff0c;C&#xff08;课程表&#xff09;&#xff0c;SC&#xff08;学生选课表&#xff09; S&#xff08;SNO&#xff0c;SNAME&#xff09;代表&#xff08;学号&#xff0c;姓名&#xff09; C&#xff08;CNO&#xff0c;CNAME&#xff0c;CTEACHER&…

SQL同时在线问题的解法

前言 同时在线相关的问题&#xff0c;在很多行业中也经常出现&#xff0c;比如&#xff1a; 统计同时最大主播数量统计同时最大在线人数统计同时最大打车人数… 很多人看到这类题&#xff0c;一脸懵逼&#xff0c;甚至连题意都看不懂&#xff0c;但是这道题是面试题中的常客&a…