使用 linkaxes 作为Yair和Amro已经建议 . 以下是您案例的快速示例
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 类型 figure_handle 下的所有对象和空标记('') . 空标记的条件是排除图例的斧柄,其标记为 legend .
如果它不仅仅是一个简单的图,那么你的图中可能还有其他轴对象 . 在这种情况下,您需要添加更多条件来标识您感兴趣的图的轴控制柄 .