Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB-如何将子图缩放到一起?_Matlab_Plot_Zooming - Fatal编程技术网

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

MATLAB-如何将子图缩放到一起?,matlab,plot,zooming,Matlab,Plot,Zooming,我在一个图中有多个子图。每个图的X轴是相同的变量(时间)。每个图上的Y轴都不同(在它表示的内容和数据的大小上) 我想要一种方法来同时放大所有绘图的时间刻度。理想情况下,在其中一个图上使用矩形缩放工具,并让其他图相应地更改其X限制。在所有这些情况下,Y极限应保持不变。自动拟合数据以在Y方向填充绘图是可以接受的 (此问题几乎与堆栈溢出问题1相同(除了))使用内置函数,如下所示: linkaxes([hAxes1,hAxes2,hAxes3], 'x'); 要获得更高级的链接(不仅仅是x轴或y轴),

我在一个图中有多个子图。每个图的X轴是相同的变量(时间)。每个图上的Y轴都不同(在它表示的内容和数据的大小上)

我想要一种方法来同时放大所有绘图的时间刻度。理想情况下,在其中一个图上使用矩形缩放工具,并让其他图相应地更改其X限制。在所有这些情况下,Y极限应保持不变。自动拟合数据以在Y方向填充绘图是可以接受的

(此问题几乎与堆栈溢出问题1相同(除了))

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

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

要获得更高级的链接(不仅仅是x轴或y轴),请使用内置功能,如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' );
第一行找到类型为“axes”和空标记(“”)的
figure\u handle
下的所有对象。空标记的条件是排除图例的斧头手柄,其标记将为
legend


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

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

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

此问题的解决方案也适用(使用内置函数LINKAXES):