Partition line in a subplot

1 次查看(过去 30 天)
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 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by