zoomed plot in the same figure

조회 수: 18 (최근 30일)
christian robledo
christian robledo 2017년 7월 17일
댓글: Jan 2017년 7월 17일
Hello i am trying to do a zoomed plot in the same figure using the plotyy function... Ive tried to play around with the explanations given here https://de.mathworks.com/matlabcentral/answers/33779-zooming-a-portion-of-figure-in-a-figure but i couldnt make it so far... The section im interested in is between the graphs plotted by (x5,y5,x6,y6) at x between 0.6 and 0.8 and y between 0.18 and 0.2.... If someboy could give me a hint i would be really greatfull. The version im using is R2012a..
Thank you very much
%Bed profile of Run 20°C
BP_num_6s_fv=xlsread('Results.xlsx','t=6s',' M3:N203');
%Velocities of Run 20°C and Run 5°C
velo6s_20=xlsread('Results.xlsx','Velocity',' I3:J203');
velo6s_5=xlsread('Results.xlsx','Velocity',' L3:M203');
% Bed profile At t=6s
x1 = BP_num_6s_fv(:,1); y1= BP_num_6s_fv(:,2);
% Velocity Run 20°C and 5°C
x5 = velo6s_20(:,1); y5 =velo6s_20(:,2);
x6 = velo6s_5(:,1); y6 =velo6s_5(:,2);
figure (1)
hold on
[ax,h1,h2]=plotyy(x1,y1,x5,y5)
h(3) = line(x6,y6, 'Parent', ax(2));
set(h(3),'Color','r')
% create a new pair of axes inside current figure
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
a=x5;
plot(a(indexOfInterest),g(indexOfInterest)) % plot on new axes
axis tight
  댓글 수: 4
Adam
Adam 2017년 7월 17일
Would it not just be easier to set the XLim and YLim properties to the desired range?
christian robledo
christian robledo 2017년 7월 17일
편집: christian robledo 2017년 7월 17일
maybe.. im just kind of starting with matlab and struggling with the basics.. could you maybe show me how i can implement it in my code? that would be awesome!
Ive tried someting like this but it just gives me like a straight line
figure (1)
hold on
[ax,h1,h2]=plotyy(x1,y1,x5,y5)
h(3) = line(x6,y6, 'Parent', ax(2));
set(h(3),'Color','r')
% create a new pair of axes inside current figure
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest1 = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
indexOfInterest2 = (y6<0.2) & (y6>0.18);
plot(indexOfInterest1,indexOfInterest2 )
axis tight

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 7월 17일
편집: Jan 2017년 7월 17일
Do you mean:
indexOfInterest = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
plot(x5(indexOfInterest), y6(indexOfInterest));
There are some zoom tools in the FileExchaage:
  댓글 수: 2
christian robledo
christian robledo 2017년 7월 17일
Hello Jan yes thanks, i think now it plots the right section.. the only thing is that it only plots one graph... In the figure were i denoted area of interest there are actually two graphs very very close to each other (x5,y5 and x6,y6).. thats why i wanted to have that zoom in plot... is there a way to make them both visible? Thanks again for your answer
Jan
Jan 2017년 7월 17일
If you know the code to plot one line, use it to draw both lines:
axes('position',[.65 .175 .25 .25], 'NextPlot', 'add')
indexOfInterest1 = (x5 < 0.8) & (x5 > 0.6);
indexOfInterest2 = (x6 < 0.8) & (x6 > 0.6);
plot(x5(indexOfInterest1), y5(indexOfInterest1));
plot(x6(indexOfInterest2), y6(indexOfInterest2));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by