How to partially apply linkaxes?

Say I have four h1-h4 plots and you want to link all their x axes. For this I can use linkaxes([h1 h2 h3 h4], 'x') . However, in addition, I want to connect the axes h1 and h3 y (as well as h2 with h4). Now when I use linkaxes([h1 h3], 'y') , the x-axis binding is lost. How can both connections be achieved at the same time?

+4
source share
2 answers

Lines 73 and 74 of linkaxes :

 %# Remove any prior links to input handles localRemoveLink(ax) 

I suggest you create a new myLinkaxes function through "Save As ...", where you comment on line 74. Even better, myLinkaxes can accept the additional "hold" input argument that is used in the if statement around lines 73 and 74, i.e. . if keep is 1, localRemoveLink not called.

This should work if you separately link the x and y axes, but if you use the 'xy' argument before or after, problems can occur.

+3
source

In addition to the solution provided by Jonas, I think it's also worth mentioning the lower-level linkprop , which is capable of linking seemingly arbitrary properties of graphic objects.

For this particular question, the desired effect can be achieved using the following sequence of commands:

 linkaxes([h1 h2 h3 h4], 'x'); lnkObj = linkprop([h1 h3], 'YLim'); 

For demo purposes (and because linkprop to me), this example is extremely simple. See the documentation and a more complex example for more details.

It can also be noted that linkprop returns a link object that (according to the previous link) should exist within the context in which you want the property connection to happen "; in particular, it seems that the connection will stop if all links to the link object disappear, reason why the target object reference variable above Furthermore, a reference to the created object communication is necessary to change the details of how the associated related graphical objects (i.e., objects have properties associated data object reference). cm. Updating ekta binding for more information (including a list of features specifically designed to perform such updates).

+2
source

Source: https://habr.com/ru/post/1345088/


All Articles