matlab 多子图,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 MATLAB))

解决方案

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的例子,展示了如何在 MATLAB 中使用 subplot() 函数来绘制多个子图。 ```matlab % 创建数据 x = -pi:0.1:pi; y1 = sin(x); y2 = cos(x); y3 = tan(x); % 绘制第一个子图 subplot(2,2,1); plot(x,y1); title('sin(x)'); % 绘制第二个子图 subplot(2,2,2); plot(x,y2); title('cos(x)'); % 绘制第三个子图 subplot(2,2,3); plot(x,y3); title('tan(x)'); % 绘制第四个子图 subplot(2,2,4); plot(x,y1,'r',x,y2,'g--',x,y3,'b:'); title('sin(x), cos(x) and tan(x)'); legend('sin(x)','cos(x)','tan(x)'); ``` 在这个例子中,我们创建了三个不同的数据集,分别是 sin(x)、cos(x) 和 tan(x)。我们使用 subplot() 函数来创建一个 2x2 的图形,并在其中绘制四个子图。 第一个 subplot() 函数调用指定了参数 2,2,1,这意味着我们正在绘制一个 2x2 的图形,并且正在绘制第一个子图。我们将 sin(x) 数据集绘制在这个子图中,并为它添加一个标题。 第二个 subplot() 函数调用指定了参数 2,2,2,这意味着我们正在绘制第二个子图。我们将 cos(x) 数据集绘制在这个子图中,并为它添加一个标题。 第三个 subplot() 函数调用指定了参数 2,2,3,这意味着我们正在绘制第三个子图。我们将 tan(x) 数据集绘制在这个子图中,并为它添加一个标题。 最后一个 subplot() 函数调用指定了参数 2,2,4,这意味着我们正在绘制最后一个子图。我们将 sin(x)、cos(x) 和 tan(x) 数据集都绘制在这个子图中,并使用 legend() 函数为数据集添加图例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值