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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by