MATLAB - 如何将子图一起缩放?

发布于 2024-10-18 04:05:38 字数 443 浏览 1 评论 0原文

我在一张图中有多个子图。每个图的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

行至春深 2024-10-25 04:05:38

使用内置的 linkaxes 函数,如下所示:

linkaxes([hAxes1,hAxes2,hAxes3], 'x');

对于更高级的链接(不仅仅是 x 或y 轴),使用内置的 linkprop 函数

Use the built-in linkaxes function as follows:

linkaxes([hAxes1,hAxes2,hAxes3], 'x');

For more advanced linking (not just the x or y axes), use the built-in linkprop function

ㄟ。诗瑗 2024-10-25 04:05:38

按照 Yair 和 Amro 的建议使用 linkaxes。以下是您的情况的一个简单示例

ha(1) = subplot(2,1,1); % get the axes handle when you create the subplot
plot([1:10]);           % Plot random stuff here as an example
ha(2) = subplot(2,1,2); % get the axes handle when you create the subplot
plot([1:10]+10);        % Plot random stuff here as an example

linkaxes(ha, 'x');      % Link all axes in x

您应该能够同时放大所有子图

如果有很多子图,并且一一收集它们的轴句柄似乎不是一种聪明的方法来完成这项工作,您可以找到所有轴通过以下命令在给定图窗句柄中进行句柄

figure_handle = figure;
subplot(2,1,1); 
plot([1:10]);   
subplot(2,1,2); 
plot([1:10]+10);

% find all axes handle of type 'axes' and empty tag
all_ha = findobj( figure_handle, 'type', 'axes', 'tag', '' );
linkaxes( all_ha, 'x' );

第一行查找 figure_handle 下类型为“axes”和空标记 ('') 的所有对象。空标签的条件是排除图例的斧柄,其标签为legend

如果您的图形不仅仅是一个简单的绘图,则可能还有其他轴对象。在这种情况下,您需要添加更多条件来识别您感兴趣的图的轴手柄。

Use linkaxes as Yair and Amro already suggested. Following is a quick example for your case

ha(1) = subplot(2,1,1); % get the axes handle when you create the subplot
plot([1:10]);           % Plot random stuff here as an example
ha(2) = subplot(2,1,2); % get the axes handle when you create the subplot
plot([1:10]+10);        % Plot random stuff here as an example

linkaxes(ha, 'x');      % Link all axes in x

You 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

figure_handle = figure;
subplot(2,1,1); 
plot([1:10]);   
subplot(2,1,2); 
plot([1:10]+10);

% find all axes handle of type 'axes' and empty tag
all_ha = findobj( figure_handle, 'type', 'axes', 'tag', '' );
linkaxes( all_ha, 'x' );

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 be legend.

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.

一直在等你来 2024-10-25 04:05:38

要用链接轴链接一对图形,请使用:

figure;imagesc(data1);
f1h=findobj(gcf,,’type’,’axes’)
figure;imagesc(data2);
f2h=findobj(gcf,,’type’,’axes’)
linkaxes([f1h,f2h],’xy’)

To link a pair of figures with linkaxes use:

figure;imagesc(data1);
f1h=findobj(gcf,,’type’,’axes’)
figure;imagesc(data2);
f2h=findobj(gcf,,’type’,’axes’)
linkaxes([f1h,f2h],’xy’)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文