zooming a portion in the same figure (MATLAB)

6 ビュー (過去 30 日間)
high speed
high speed 2022 年 2 月 6 日
編集済み: DGM 2022 年 2 月 6 日
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:

採用された回答

DGM
DGM 2022 年 2 月 6 日
編集済み: DGM 2022 年 2 月 6 日
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')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by