linkaxes and hold on issues
이전 댓글 표시
Hi i noticed that when i use linkaxes in combination with hold on i don't get the result i expect.
My objective is to draw polygons at different times in a main figure while keeping a secondary figure axis extent aligned to the main one.
can someone explain why this happens and, more importantly, what should i do to obtain the expected behaviour?
i'll brake the process down in two stages to clarify the unexpected behaviour.
- Stage 1 - drawing the two figures on the main axis completely disregarding the secondary axis.
- Stage 2 - adding the secondary into play with linkaxes
Stage 1
ah_main=subplot(1,2,1); %main axis
ah_secondary=subplot(1,2,2); %secondary axis
smallBox.x=[0 1 1 0 0];
smallBox.y=[0 0 1 1 0];
bigBox.x=smallBox.x*3 + 2;
bigBox.y=smallBox.y*3;
hold(ah_main,'on')
plot(ah_main,smallBox.x,smallBox.y,'r', 'linewidth',2)
plot(ah_main,bigBox.x,bigBox.y,'g', 'linewidth',2)
as expected the figure resulting from the execution of this code is:

Stage 2 If i insert a linkaxes before drawing the figures then the behaviour even on the main axis is completely different: the axis limits are not scaled any longer.
ah_main=subplot(1,2,1); %main axis
title('Main axis')
ah_secondary=subplot(1,2,2); %secondary axis
title('Secondary axis')
smallBox.x=[0 1 1 0 0];
smallBox.y=[0 0 1 1 0];
bigBox.x=smallBox.x*3 + 2;
bigBox.y=smallBox.y*3;
linkaxes([ah_main ah_secondary]);
hold(ah_main,'on')
plot(ah_main,smallBox.x,smallBox.y,'r', 'linewidth',2)
plot(ah_main,bigBox.x,bigBox.y,'g', 'linewidth',2)

Any clues?
Thank you very much for your time.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!