zooming a portion in the same figure (MATLAB)

6 views (last 30 days)
Dear members,
I want to know how to zoom a part in MATLAB figures and put it in the same figure as in this example:

Accepted Answer

DGM
DGM on 6 Feb 2022
Edited: DGM on 6 Feb 2022
Here's a start:
% some simulant data
xr = [0 pi];
x = linspace(xr(1),xr(2),100);
y1 = -cos(x);
y2 = -0.95*cos(0.99*x);
% do the main plots, keep the handles
h(1) = plot(x,y1); hold on
h(2) = plot(x,y2,':');
grid on
xlim(xr)
% create roi box
rrx = [1 1.25]; % roi extents x
rry = [-0.5 -0.4]; % roi extents y
plot(rrx([1 1 2 2 1]),rry([2 1 1 2 2]),'k:') % box
% these lines are just manually positioned so that they avoid the labels
plot([2 rrx(2) rrx(2) 2],[-0.2 rry(2) rry(1) -0.62],'k:')
% add inner axes for roi
hax1 = gca; % save this handle in case it's needed later
hax2 = axes('position',[0.65 0.25 0.2 0.2]);
% the same plot commands, but with different xlim, ylim
plot(x,y1); hold on
plot(x,y2,':')
grid on
xlim(rrx)
ylim(rry)
% explicitly set up legend using only the handles for the first two plots
legend(h,{'thing','other thing'},'location','northwest')

More Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!