Behaviour of axis properties with 'yyaxis'

前端 未结 1 1789
鱼传尺愫
鱼传尺愫 2021-01-20 23:39

Create a figure with two y-axes, using yyaxis:

figure
yyaxis left
hl = plot([0 10],[0 10],\'-\');
yyaxis right
hr = plot([0 10],[10 0],\'--\');

相关标签:
1条回答
  • 2021-01-21 00:29

    To me it looks like yyaxis does some nasty-behind-the-scenes things and there's lots of hidden data we can't access.

    The documentation does say that:

    yyaxis left activates the side of the current axes associated with the left y-axis. Subsequent graphics commands target the left side.

    and

    The Children property of the Axes object only contains the children for the active side. To access all the children for both sides, use the allchild function.

    Changing the "side" with yyaxis therefore changes the contents of the Axes object, I presume that the contents for the other side gets stored in some hidden location that I haven't been able to find. yyaxis is P-code, so we won't be able to figure out what exactly it is doing.

    This is interesting:

    figure
    yyaxis left
    hl = plot([0 10],[0 1],'-');
    yyaxis right
    hr = plot([0 10],[100 0],'--');
    
    h = gca;
    
    yyaxis left
    h.YLim
    
    yyaxis right
    h.YLim
    

    The code creates left and right axes with different limits. We get the handle to the axes, change to left, read the limits from the handle, then change to right and read the same property again. The first time it returns [0,1], the second time it is [0,100]. That is, the Axes object with handle h changes when we call yyaxis.

    The only indication I've found that h points to axes with two sides is that h.YAxis returns two handles to NumericRuler objects, one for each side.


    I can't but feel this is awkward behavior. I would have expected there to be two Axes objects, both with the same Position property, and maybe with listeners that keep the two in sync.

    0 讨论(0)
提交回复
热议问题