How can I plot my figures like attached plots?

Hi,
I want plot two graphs on same plot but with different x axis limits. Just given in the figure (a) attached to this question. How can I do it?
Second, if two plots are making crossover/overlapping at some points. Is it possible two a fill any color (yellow) in the overlapped area. as shown in the attached figure (b)?
Regards,
Ahmed

 Accepted Answer

Hi Nisar,
(1) You could use axes to add multiple axes to the same figure & then alter their properties as per your requirements. You could also use text command to add text to the plot. Example:
figure(1)
ax1 = axes;
ax2 = axes;
x1 = [1.95:0.1:2.95];
y1 = 2.5*ones(length(x1),1);
x2 = [-0.5:0.1:0.5];
y2 = 3*ones(length(x2),1);
plot(ax1,x1,y1,'r');
hold on
plot(ax2,x2,y2,'b');
hold off
ax2.YLim = [1 5];
ax1.YLim = ax2.YLim;
ax2.XLim = [-2 0.5];
ax1.XLim = [1.95 2.95];
ax2.Visible = "off";
set(ax1,'Yticklabel',{})
set(ax1,'Xticklabel',{})
(2) You could use patch function to fill the overlapped area in the plot. Example:
x=0:0.1:10;
y1 = randn(1,length(x));
y2 = randn(1,length(x));
figure
hold all
plot(x,y1)
plot(x,y2)
patch([x fliplr(x)], [y1 fliplr(y2)], 'g')
hold off
Hope this helps!

4 Comments

Hi Pavan,
Thanka for the answer, I am using following command to plot
figure(2),
xlabels{1} = 'DEN (gm/cm3)';
xlabels{2} = 'NPHI(.frac)';
ylabels{1} = 'Depth(m)';
ylabels{2} = 'Depth(m)';
[ax,hlT,hlS] = plotxx(DEN,Depth,NEU,Depth,xlabels,ylabels);
set(ax(2),'xlim',[-0.15 0.45]);
set(ax(2),'xdir', 'reverse');
set(ax(2),'ylim',[1910 1980]);
set(ax(1),'ylim',[1910 1980]);
set(ax(1),'ydir', 'reverse');
set(ax(1),'xlim',[1.95 2.95]);
set(ax(2),'ydir', 'reverse');
Can you please help to write the code for color shading according to this code. the area I want to shaed is from 1917 - 1967 on y-axis.
Hi,
The first part is working. however, the second part is not working.
See my latest Comment for the rotated version.
@Star Strider Thank you very much for your detail reply. Yes, it is solved.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!