Partition line in a subplot

조회 수: 1 (최근 30일)
Reji G
Reji G 2023년 6월 5일
댓글: Reji G 2023년 6월 5일
How can I add partition line to a subplot in matlab(Hand sketch is attached for reference).
clc;close all; clear all;
x=[1 2 5 4 6 7];
y=[5 6 2 5 8 4];
subplot(4,3,1);plot(x,y);
subplot(4,3,2);plot(x,y);
subplot(4,3,3);plot(x,y);
subplot(4,3,4);plot(x,y);
subplot(4,3,5);plot(x,y);
subplot(4,3,6);plot(x,y);
subplot(4,3,7);plot(x,y);
subplot(4,3,8);plot(x,y);
subplot(4,3,9);plot(x,y);
subplot(4,3,10);plot(x,y);
subplot(4,3,11);plot(x,y);
subplot(4,3,12);plot(x,y);

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 6월 5일
You can do this by turning clipping off and manually drawing lines -
clc;close all; clear all;
x=[1 2 5 4 6 7];
y=[5 6 2 5 8 4];
subplot(4,3,1);plot(x,y);
%1st vertical line
%Clipping off
set(gca,'Clipping','Off')
xl = xlim;
yl = ylim;
%Make lines according to the x and y limits of the plot
%change x and y values as required
%Note that you will have to manually adjust these for different data
h = line(max(xl)+[1 1],[-25 max(ylim)+2.5]);
%Set line properties as required
set(h,'LineWidth',1,'LineStyle','--','Color','r')
%Adjust xlimits back to original
xlim(xl)
subplot(4,3,2);plot(x,y);
%2nd vertical line
%Clipping off
set(gca,'Clipping','Off')
xl = xlim;
yl = ylim;
%Make lines according to the x and y limits of the plot
%change x and y values as required
%Note that you will have to manually adjust these for different data
h = line(max(xl)+[1 1],[-25 max(ylim)+2.5]);
%Set line properties as required
set(h,'LineWidth',1,'LineStyle','--','Color','r')
%Adjust xlimits back to original
xlim(xl)
subplot(4,3,3);plot(x,y);
subplot(4,3,4);plot(x,y);
subplot(4,3,5);plot(x,y);
subplot(4,3,6);plot(x,y);
subplot(4,3,7);plot(x,y);
subplot(4,3,8);plot(x,y);
%1st vertical line
%Clipping off
set(gca,'Clipping','Off')
xl = xlim;
yl = ylim;
%Make lines according to the x and y limits of the plot
%change x and y values as required
%Note that you will have to manually adjust these for different data
h = line([-10 17.5], max(yl)+[1 1]);
%Set line properties as required
set(h,'LineWidth',1,'LineStyle','--','Color','r')
%Adjust ylimits back to original
ylim(yl)
subplot(4,3,9);plot(x,y);
subplot(4,3,10);plot(x,y);
subplot(4,3,11);plot(x,y);
subplot(4,3,12);plot(x,y);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by