MATLAB - 如何将子图一起缩放?
我在一张图中有多个子图。每个图的 X 轴是相同的变量(时间)。每个图上的 Y 轴都不同(无论是它所代表的内容还是数据的大小)。
我想要一种同时放大所有图的时间尺度的方法。理想情况下,可以在其中一张图上使用矩形缩放工具,并让其他图相应地更改其 X 限制。对于所有这些,Y 限制应保持不变。自动拟合数据以填充 Y 方向的绘图是可以接受的。
(这个问题与 Stack Overflow 问题一几乎相同Matplotlib/Pyplot:如何将子图一起缩放?(MATLAB 除外))
I have multiple subplots in one figure. The X axis of each plot is the same variable (time). The Y axis on each plot is different (both in what it represents and the magnitude of the data).
I would like a way to zoom in on the time scale on all plots simultaneously. Ideally by using the rectangle zoom tool on one of the plots, and having the other plots change their X limits accordingly. The Y limits should remained unchanged for all of this. Auto fitting the data to fill the plot in the Y direction is acceptable.
(This question is almost identical to Stack Overflow question one Matplotlib/Pyplot: How to zoom subplots together? (except for MATLAB))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用内置的 linkaxes 函数,如下所示:
对于更高级的链接(不仅仅是 x 或y 轴),使用内置的 linkprop 函数
Use the built-in linkaxes function as follows:
For more advanced linking (not just the x or y axes), use the built-in linkprop function
按照 Yair 和 Amro 的建议使用
linkaxes
。以下是您的情况的一个简单示例您应该能够同时放大所有子图
如果有很多子图,并且一一收集它们的轴句柄似乎不是一种聪明的方法来完成这项工作,您可以找到所有轴通过以下命令在给定图窗句柄中进行句柄
第一行查找
figure_handle
下类型为“axes”和空标记 ('') 的所有对象。空标签的条件是排除图例的斧柄,其标签为legend
。如果您的图形不仅仅是一个简单的绘图,则可能还有其他轴对象。在这种情况下,您需要添加更多条件来识别您感兴趣的图的轴手柄。
Use
linkaxes
as Yair and Amro already suggested. Following is a quick example for your caseYou should be able to zoom in all the subplots simultaneously
If there are many subplots, and collecting their axes handle one by one does not seem a clever way to do the job, you can find all the axes handle in the given figure handle by the following commands
The first line finds all the objects under
figure_handle
of type "axes" and empty tag (''). The condition of the empty tag is to exclude the axe handles of legends, whose tag will belegend
.There might be other axes objects in your figure if it's more than just a simple plot. In such case, you need to add more conditions to identify the axes handles of the plots you are interested in.
要用链接轴链接一对图形,请使用:
To link a pair of figures with linkaxes use: