Horizontal line common to 2 graphs

2 visualizaciones (últimos 30 días)
John
John el 13 de Sept. de 2015
Respondida: Walter Roberson el 13 de Sept. de 2015
I have two graphs in two different figures. Is it possible to have them side by side in the same figure with a horizontal line going from one to the other? (hard to explain in words; it's meant to be like the green line in the attached figure)
clc;
close all;
clear all;
n1 = 3;
x = linspace(0,25,n1);
y = 100 - 4*x;
x2 = linspace(0,40,n1);
y2 = 100 - 2.5*x2;
s1 = linspace(0,4,n1);
s2 = 4.*ones(1,n1);
s3 = linspace(4,5,n1);
s = cat(2,s1,s2,s3);
xs1 = zeros(1,n1);
xs2 = linspace(0,25,n1);
xs3 = 25.*ones(1,n1);
xs = cat(2,xs1,xs2,xs3);
dt = 25.*ones(1,n1);
dx=linspace(12.5,25,n1);
dy=-(dx-22.5)/2.5;
dt11 = 12.5.*ones(1,n1);
s21 = linspace(0,2.5,n1);
s22 = 2.5.*ones(1,n1);
s23 = linspace(2.5,5,n1);
s2 = cat(2,s21,s22,s23);
xs21 = zeros(1,n1);
xs22 = linspace(0,40,n1);
xs23 = 40.*ones(1,n1);
xs2 = cat(2,xs21,xs22,xs23);
dt2 = 40.*ones(1,n1);
dx2=linspace(24,32,n1);
dy2=(dx2-19)/2;
dt22 = 24.*ones(1,n1);
xlb=0;
xub=45;
xubtick=25;
figure('name','figure 1','number','off');
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 2.8 2]);
plot(xs,s,'Color','red');
xlabel('quantity flow')
ylabel('$\bigl.\frac{L_l}{L_w}\bigr.$','Interpreter','latex','rot',0)
set(gca,...
'Units','normalized',...
'FontUnits','points',...
'FontWeight','normal',...
'FontSize',9,...
'FontName','Times',...
'XLim',[xlb xub],...
'XTick',[0,12.5,25],...
'YTick',0:1:4,...
'YLim',[0 5],...
'Box','off')
set(gca, 'Position', get(gca, 'OuterPosition') - ...
get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);
hold on;
plot(dx,dy,'Color','blue');
hleg1 = legend('curve 1','curve 2');
legend('Location','best');
plot(dt,s1,':','color',[.75 .75 .75]);
plot(dt11,s1,':','color',[.75 .75 .75]);
hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xlb=0;
xub=45;
xubtick=40;
figure('name','figure 2','number','off');
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 2.8 2]);
plot(xs2,s2,'Color','red');
xlabel('quantity flow')
ylabel('$\bigl.\frac{L_l}{L_w}\bigr.$','Interpreter','latex','rot',0)
set(gca,...
'Units','normalized',...
'FontUnits','points',...
'FontWeight','normal',...
'FontSize',9,...
'FontName','Times',...
'XLim',[xlb xub],...
'XTick',[0,24,40],...
'YTick',[0,1,2.5,4],...
'YLim',[0 5],...
'Box','off')
set(gca, 'Position', get(gca, 'OuterPosition') - ...
get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);
hold on;
plot(dx2,dy2,'Color','blue');
hleg1 = legend('curve 1','curve 2');
legend('Location','best');
plot(dt2,s21,':','color',[.75 .75 .75]);
plot(dt22,s21,':','color',[.75 .75 .75]);
hold off;

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Sept. de 2015
It is not possible to have a line between two figures. In MATLAB, "figure" refers to windows.
It is possible to have a line between two axes in a single figure.
The easiest way to do that is to create a third axes, set the axes 'visible' off (so you do not see the labels and so on), set the axes background color to 'none', and have the position overlap the two existing axes and then draw the line.
A

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by