【问题标题】:MATLAB - How to zoom subplots together?MATLAB - 如何一起缩放子图?
【发布时间】:2011-06-28 17:29:01
【问题描述】:

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

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

(这个问题几乎和 Stack Overflow 问题一一样Matplotlib/Pyplot: How to zoom subplots together?(除了MATLAB))

【问题讨论】:

标签: matlab plot zooming


【解决方案1】:

使用内置的linkaxes函数如下:

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

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

【讨论】:

    【解决方案2】:

    按照 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

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2011-05-11
        • 2016-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多