Making a Plot inset?

36 ビュー (過去 30 日間)
MeitiLuk
MeitiLuk 2020 年 11 月 6 日
コメント済み: MeitiLuk 2020 年 11 月 6 日
So this is my Code
% 1 Hz
i =1;
figure(1)
I plot my 4 lines in one plot
subplot(2,2,i)
hold on;
plot(Freq_0k4 {1,i}(1,:), Moment_0k4 {1,i}(:,1),'k');
plot(Freq_1k6 {1,i}(1,:), Moment_1k6 {1,i}(:,1),'r');
plot(Freq_3k2 {1,i}(1,:), Moment_3k2 {1,i}(:,1),'m');
plot(Freq_4k8 {1,i}(1,:), Moment_4k8 {1,i}(:,1),'b');
xlim([0 10]);
legend('0,4°','1,6°','3,2°','4,8°');
legend('boxoff');
xlim([0 10]);
grid on;
Then I would like to make an inset, where you have a kind of zoomed in section, to see which is above which line.
p = get(gca, 'Position');
h = axes('Parent', gcf, 'Position', [p(1)+0.05 p(2)+0.2 p(3)-0.25 p(4)-0.2]);
plot(h, Freq_0k4 {1,i}(1,:), Moment_0k4 {1,i}(:,1),'k');
plot(h, Freq_1k6 {1,i}(1,:), Moment_1k6 {1,i}(:,1),'r');
plot(h, Freq_3k2 {1,i}(1,:), Moment_3k2 {1,i}(:,1),'m');
plot(h, Freq_4k8 {1,i}(1,:), Moment_4k8 {1,i}(:,1),'b');
set(h, 'Xlim', [0.9 1.1], 'Ylim', [4 5.2]);
grid on;
hold off;
unfortunatly with this inset only the last 'blue' line is getting plotted.
Can anybody help me with this?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 6 日
You need to call hold on the new axes too
p = get(gca, 'Position');
h = axes('Parent', gcf, 'Position', [p(1)+0.05 p(2)+0.2 p(3)-0.25 p(4)-0.2]);
hold(h); % <--- add this line
plot(h, Freq_0k4 {1,i}(1,:), Moment_0k4 {1,i}(:,1),'k');
plot(h, Freq_1k6 {1,i}(1,:), Moment_1k6 {1,i}(:,1),'r');
plot(h, Freq_3k2 {1,i}(1,:), Moment_3k2 {1,i}(:,1),'m');
plot(h, Freq_4k8 {1,i}(1,:), Moment_4k8 {1,i}(:,1),'b');
  1 件のコメント
MeitiLuk
MeitiLuk 2020 年 11 月 6 日
Yes I just found out by my self :D

サインインしてコメントする。

その他の回答 (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