subplot内のf​igureにinse​tを入れる方法につい​て

通常のfigureにinsetを入れる場合は,例えば
close all;
x1 = 0:0.01:pi;
x2 = 0:0.01:pi/6;
y1 = sin(x1);
y2 = sin(x2);
plot(x1,y1);
axes('Position',[.7 .7 .2 .2]);
box on
plot(x2,y2);
とすれば実装できます.
しかし,subplot内のfigureにinsetを入れようとして,同様に以下のようなコードを実行すると,1つ目の図に入れたはずのinsetが表示されません.
close all;
figure('Position', [50 50 1000 400]);
x1 = 0:0.01:pi;
x2 = 0:0.01:pi/6;
y1 = sin(x1);
y2 = sin(x2);
z1 = cos(x1);
subplot(1,2,1)
plot(x1,y1);
axes('Position',[.7 .7 .2 .2]);
box on
plot(x2,y2); %これが表示されない
subplot(1,2,2)
plot(x1,z1);
どのように書けば,subplot内のfigureにinsetを入れることができるのでしょうか?

 Akzeptierte Antwort

1 Stimme

質問者様のコードでは、insetさせるAxesが、subplot(1,2,2)の下に配置されてしまって表示が見えなくなってしまっています。
そのため、insetさせるAxesはsubplot(1,2,2)の後に記述し、前面に表示させる必要があります。
close all;
figure('Position', [50 50 1000 400]);
x1 = 0:0.01:pi;
x2 = 0:0.01:pi/6;
y1 = sin(x1);
y2 = sin(x2);
z1 = cos(x1);
subplot(1,2,1);
plot(x1,y1);
subplot(1,2,2);
plot(x1,z1);
axes('Position',[.7 .7 .2 .2]);
box on
plot(x2,y2);

1 Kommentar

Kato Yusuke
Kato Yusuke am 21 Aug. 2023
なるほど,早速ありがとうございました!
この場合,Positionの数値はsubplot全体に対応していて,これを調整すれば,1つ目の図中にinsetを入れることも可能ですね!
助かりました,どうもありがとうございました.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2021b

Community Treasure Hunt

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

Start Hunting!