如何部分应用连杆?
假设我有四个图 h1-h4 并且想要链接它们所有的 x 轴。为此,我可以使用linkaxes([h1 h2 h3 h4], 'x')
。然而,此外我想链接 h1 和 h3 的 y 轴(以及 h2 到 h4 的)。现在,当我使用 linkaxes([h1 h3], 'y') 时,x 轴链接丢失。如何同时实现这两种链接?
Say I have four plots h1-h4 and want to link all their x-axes. For that I can use linkaxes([h1 h2 h3 h4], 'x')
. However, in addition I want to link h1 and h3's y-axes (and also h2's to h4's). Now when I use linkaxes([h1 h3], 'y')
the x-axes linking is lost. How can both linkings be achieved at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
linkaxes
的第 73 和 74 行是:我建议您通过“另存为...”创建一个新函数
myLinkaxes
,在其中注释掉第 74 行。更好, myLinkaxes 可以接受额外的输入参数“keep”,该参数在第 73 行和第 74 行周围的 if 子句中使用,即如果keep
为 1,则localRemoveLink
未被调用。如果您单独链接 x 轴和 y 轴,这应该可以工作,但如果您在之前或之后使用
'xy'
参数,则可能会出现问题。Lines 73 and 74 of
linkaxes
are:I suggest you create a new function,
myLinkaxes
, via "Save As...", where you comment out line 74. Even better,myLinkaxes
could accept an additional input argument "keep", which is used in an if-clause around lines 73 and 74, i.e. ifkeep
is 1,localRemoveLink
is not called.This should work if you separately link x and y-axes, but if you use the
'xy'
argument before or after, there might be trouble.除了 Jonas 提供的解决方案之外,我认为还值得一提的是较低级别的函数
linkprop
,它能够链接图形对象看似任意的属性。对于这个特定的问题,可以通过以下命令序列实现所需的效果:
出于演示目的(并且因为
linkprop
对我来说是新的),这个示例非常简单。请参阅文档了解更多详细信息和更复杂的示例。这里还值得一提的是
linkprop
返回一个 链接对象,(根据上一个链接)“必须存在于您希望发生属性链接的上下文中”;特别是,如果对链接对象的所有引用消失,链接似乎将停止,这就是将链接对象分配给上面的变量的原因。此外,为了改变相应的图形对象如何链接的细节(即,哪些对象的属性由给定的链接对象链接),对所创建的链接对象的引用是必要的;有关详细信息(包括专门为执行此类更新而设计的功能列表)。In addition to the solution provided by Jonas, I think that it is also worth mentioning the lower-level function
linkprop
, which is capable of linking seemingly arbitrary properties of graphics objects.For this particular question, the desired effect can be achieved via the following sequence of commands:
For demonstrative purposes (and because
linkprop
is new to me), this example is extremely simple. Please see the documentation for more details and a more complex example.It may also be worth mentioning here that
linkprop
returns a link object, which (according to the previous link) "must exist within the context where you want property linking to occur"; in particular, it seems to be the case that linking will cease if all references to the link object disappear, thus the reason for assigning the link object to a variable above. Moreover, a reference to the created link object is necessary for changing the details of how the corresponding graphics objects are linked (i.e., which objects' properties are linked by the given link object); see Updating a Link Object for more information (including a list of functions designed specifically for the purpose of performing such updates).