1.以纵坐标为分割
clear;clc;
data = load("折线图需要的数据.mat");
data = data.data;
color = [0.933333333333333 0.815686274509804 0.847058823529412;
0.690196078431373 0.643137254901961 0.894117647058824;
0.800000000000000 0.643137254901961 0.890196078431373];
x = 1:length(data);
limit1 = 6;
limit2 = 12;
x1 = find(data < limit1);
x2=find((data>=limit1)&(data<=limit2));
x3 = find(data > limit2);
for i = 2:length(data)
A1 = find(x1 == i);
A2 = find(x2 == i);
A3 = find(x3 == i);
if ~isempty(A1)
num = 1;
elseif ~isempty(A2)
num = 2;
else
num =3;
end
plot(i-1:i,data(i-1:i),'LineWidth',2,'Color',color(num,:))
hold on
end
plot(x,limit1*ones(1,length(x)),'--k','LineWidth',1);
hold on
plot(x,limit2*ones(1,length(x)),'--k','LineWidth',1);
hold on
xlabel("自变量");
ylabel("因变量","Rotation",0);
set(gca,"FontSize",12,"LineWidth",1.5);
box off
2.以纵坐标分割结果展示
3.以横坐标为分割
clear;clc;
data = load("折线图需要的数据.mat");
data = data.data;
color = [0.933333333333333 0.815686274509804 0.847058823529412;
0.690196078431373 0.643137254901961 0.894117647058824;
0.800000000000000 0.643137254901961 0.890196078431373];
limit = 600;
plot(1:limit,data(1:limit),'LineWidth',2,'Color',color(1,:));
hold on
plot(limit:length(data),data(limit:end),'LineWidth',2,'Color',color(2,:));
hold on
y = get(gca,'YLim');
plot([limit limit], [y(1),y(2)],'--k','LineWidth',0.3);
hold on
xlabel("自变量");
ylabel("因变量","Rotation",0);
h = legend("训练值","预测值");
set(h,'FontSize',11,'FontWeight','normal','box','off')
set(gca,"FontSize",12,"LineWidth",1.5);
box off
4.以横坐标分割结果展示