clear; clc; close all figure set(gcf,'Position',[50,50,1050,450]) xticks = {'AIM', 'CA', 'COV', 'FES', 'GBVS', 'MC', 'PCA', 'RBD', 'SeR', 'SIM', 'SUN', 'SWD', 'GR'}; N = 13; % load('bar3.mat'); % 模拟数据 p1 = round(rand(1,N)*10)+1; p2 = round(rand(1,N)*10)+1; p3 = round(rand(1,N)*10)+1; p4 = round(rand(1,N)*10)+1; b1 = ones(1,N); b2 = 2*ones(1,N); b3 = 3*ones(1,N); b4 = 4*ones(1,N); %% =============绘制第1组=================== X = [p1;p2;p3;p4]; B = [b1;b2;b3;b4]; X(2:4,:) = 0; % 第2、3、4组数据置零 B(2:4,:) = 0; data = cat(1,X,zeros(1,N)); Y1 = reshape(data,N*5,1); data = cat(1,B,zeros(1,N)); Y2 = reshape(data,N*5,1); barH1 = bar([Y1,Y2],'stack'); set(gca,'XLim',[0 65],'XTick',2:5:62,'XTickLabel',xticks); % ch = get(myBar,'children'); set(barH1(1),'facecolor',[38,54,129]./255) set(barH1(2),'facecolor',[255,217,47]./255) hold on %%=============绘制第2组=================== X = [p1;p2;p3;p4]; B = [b1;b2;b3;b4]; X([1,3,4],:) = 0; % 第1、3、4组数据置零 B([1,3,4],:) = 0; data = cat(1,X,zeros(1,N)); Y1 = reshape(data,N*5,1); data = cat(1,B,zeros(1,N)); Y2 = reshape(data,N*5,1); barH2 = bar([Y1,Y2],'stack'); set(gca,'XLim',[0 65],'XTick',2:5:62,'XTickLabel',xticks); % ch = get(myBar,'children'); set(barH2(1),'facecolor',[104,191,193]./255) set(barH2(2),'facecolor',[255,217,47]./255) hold on %%=============绘制第3组=================== X = [p1;p2;p3;p4]; B = [b1;b2;b3;b4]; X([1,2,4],:) = 0; % 第1、2、4组数据置零 B([1,2,4],:) = 0; data = cat(1,X,zeros(1,N)); Y1 = reshape(data,N*5,1); data = cat(1,B,zeros(1,N)); Y2 = reshape(data,N*5,1); barH3 = bar([Y1,Y2],'stack'); set(gca,'XLim',[0 65],'XTick',2:5:62,'XTickLabel',xticks); % ch = get(myBar,'children'); set(barH3(1),'facecolor',[44,160,44]./255) set(barH3(2),'facecolor',[255,217,47]./255) hold on %%=============绘制第4组=================== X = [p1;p2;p3;p4]; B = [b1;b2;b3;b4]; X([1,2,3],:) = 0;% 第1、2、3组数据置零 B([1,2,3],:) = 0; data = cat(1,X,zeros(1,N)); Y1 = reshape(data,N*5,1); data = cat(1,B,zeros(1,N)); Y2 = reshape(data,N*5,1); barH4 = bar([Y1,Y2],'stack'); set(gca,'XLim',[0 65],'XTick',2:5:62,'XTickLabel',xticks); % ch = get(myBar,'children'); set(barH4(1),'facecolor',[0,184,229]./255) set(barH4(2),'facecolor',[255,217,47]./255) hold on set(gca,'FontSize',18,'FontName','Times New Roman') legendH = legend([barH1(1),barH2(1),barH3(1),barH4(1),barH4(2)],{'CC','sAUC','AUC\_J','NSS','increase'}); % 设置legend水平摆放,防止覆盖图表 set(legendH,'Orientation','horizon')
|