Making a Plot inset?

조회 수: 17 (최근 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 CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by