zoomed plot in the same figure
19 views (last 30 days)
Show older comments
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 Comments
Adam
on 17 Jul 2017
Would it not just be easier to set the XLim and YLim properties to the desired range?
Accepted Answer
Jan
on 17 Jul 2017
Edited: Jan
on 17 Jul 2017
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 Comments
Jan
on 17 Jul 2017
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));
More Answers (0)
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!