필터 지우기
필터 지우기

linkaxes and hold on issues

조회 수: 9 (최근 30일)
Marco
Marco 2014년 11월 20일
댓글: Marco 2014년 11월 20일
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.

채택된 답변

Adam
Adam 2014년 11월 20일
편집: Adam 2014년 11월 20일
linkaxes sets the XLimMode and YLimMode properties to 'manual'
Try inserting
ah_main.XLimMode = 'auto';
ah_main.YLimMode = 'auto';
or
set( ah_main, 'XLimMode', 'auto' )
set( ah_main, 'YLimMode', 'auto' )
if you are working in R2014a or earlier or wish to retain backwards compatibility.
between your linkaxes instruction and the plotting instruction.
By the way, I don't know if this is documented anywhere with regard to linkaxes, I just took a look at axes properties after running your code and noticed the fact. Having noticed it it is not surprising I guess as a side-effect of linkaxes, but not obvious before seeing it! More obvious behaviour would have been for it to keep the main axes as 'auto' and switch any linked axes to 'manual' mode I would have thought.
  댓글 수: 1
Marco
Marco 2014년 11월 20일
that worked great, thanks!
thumbs up for your answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by