Matlab箱线图分组叠加折线图

您所在的位置:网站首页 matlab坐标轴刻度线函数 Matlab箱线图分组叠加折线图

Matlab箱线图分组叠加折线图

2023-06-08 13:58| 来源: 网络整理| 查看: 265

%分组group箱线图和折线图的合并版本

%% clear data

%% edge color

edgecolor1=[0.8,0.8,0.8]; % white color:[1,1,1],如果设置成了白色就没有箱子线图边框

edgecolor2=[0.8,0.8,0.8]; % white color

edgecolor3=[0.8,0.8,0.8]; % white color

position_1 = [0.8:1:4.8]; % define position for first group boxplot

position_2 = [1.0:1:5.0]; % define position for second group boxplot

position_3 = [1.2:1:5.2]; % define position for second group boxplot

%分别农村箱线图和对应平均值和中位数的折线图,注意boxplot当有横坐标还想设置位置时用position

figure(2)

box_1 = boxplot(CALCULATE_data_nc,t_nc,'positions',position_1,'colors', ...

edgecolor1,'width',0.1,'notch','on','symbol','');

hold on;

p1=plot(position_1,mean_nc,'o',position_1,med_nc,'-')

p1(2).LineWidth = 1;%set median linewidth to 1

p1(2).Color = [.6,.1,.3];p1(1).Color = [.6,.1,.3];%set color of both mean and media

hold on

box_2 = boxplot(CALCULATE_data_CZ,t_CZ,'positions',position_2,'colors', ...

edgecolor2,'width',0.1,'notch','on','symbol','');

hold on;

p2=plot(position_2,mean_CZ,'o',position_2,med_CZ,'-')

p2(2).LineWidth = 1;%set median linewidth to 1

p2(2).Color = [.5,.5,.5];p2(1).Color = [.5,.5,.5];%set color

hold on

box_3 = boxplot(CALCULATE_data_QT,t_QT,'positions',position_3,'colors', ...

edgecolor3,'width',0.1,'notch','on','symbol','');

p3=plot(position_3,mean_QT,'o',position_3,med_QT,'-')

p3(2).LineWidth = 1;%set median linewidth to 1

p3(2).Color = [.6,.2,.6];p3(1).Color = [.6,.2,.6];%set color

ylim([-10, 300]);%设置y坐标轴

set(gca,'XTick', [1 2 3 4 5]);%设置x坐标轴每一个时间点的位置和间隔

%如果要分组填写颜色:

fillcolor1=[0 0 0]/255; % fillcolors = rand(24, 3);

fillcolor2=[190 190 190]/255;

fillcolor3=[220 220 220]/255;

fillcolors=[repmat(fillcolor1,5,1);repmat(fillcolor2,5,1);repmat(fillcolor3,5,1)];

boxobj = findobj(gca,'Tag','Box');

a=length(boxobj)

for j=1:a

patch(get(boxobj(j),'XData'),get(boxobj(j),'YData'),fillcolors(j,:),'FaceAlpha',0.1);

end

%%% 每一个legend之间都要加上该语句,即可建立新的legend,而不会覆盖之前的

h1=legend(p2,['mean_CZ','med_CZ'],{"Mean DNB", "Median DNB"});

% 设置h1的位置和大小

set(h1,'Location','North','units','normalized','FontName','Times New Roman');

ylabel('Radiance(nW·cm-2·sr-1','FontName','Times New Roman')

xlabel('Date','FontName','Times New Roman')

title('NTL Changes in Different Regions(Median)','FontName','Times New Roman','FontWeight','bold','FontSize',12);

%set(box_1,'LineWidth',1.5);%1设置每个框的粗细

%set(box_2,'LineWidth',1.5);

%set(box_3,'LineWidth',1.5);

%text 函数的前两个输入参数指定位置。第三个参数指定了文本。

txt = 'Urban built-up areas';

t= text(5.2,180,txt,'FontName','Times New Roman','FontWeight','bold')

t.Rotation = 90

txt = 'Rural settlements';

t= text(5.0,23,txt,'FontName','Times New Roman','FontWeight','bold')

t.Rotation = 90

txt = 'Vegetation-dominatied areas';

t= text(5.4,3,txt,'FontName','Times New Roman','FontWeight','bold')

t.Rotation = 90



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3