# Partition line in a subplot

2 次查看（过去 30 天）
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 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')
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')
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')
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);
Reji G 2023-6-5
Thank you. Charm

### 类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by