MATLAB 使用 subplot 确定 子图的大小与相对位置 subplot(‘Position‘,pos)

使用 subplot的 position 用法

绘制子图时,可以使用 tight_subplot 函数,这里MATLAB 官方的subplot 函数也能达到相同的效果。
在这里插入图片描述

subplot(‘Position’,pos) creates axes in the custom position specified by pos. Use this option to position a subplot that does not align with grid positions. Specify pos as a four-element vector of the form [left bottom width height]. If the new axes overlap existing axes, then the new axes replace the existing axes.

pos向量 为**[left bottom width height]**,可以调节任意子图的大小 与相对位置,这是相比 tight_subplot 函数的一个优点。
下面 列举几个常见的pos 矩阵,在以后的绘图中能起到直接套用的作用。一个主要的思想是上下子图之间的间隙可以小(因为是对齐的,只需在最下面一个子图标注横坐标轴),而左右子图之间的间隙应该更大,便于标注出纵坐标的值。

2 × 2 的子图 【子图顺序为 先行后列,从左往右】
pos = zeros(4,4); % [left bottom width height]
pos(:,3) = 0.44; pos(:,4) = 0.44;
pos([1 3],1) = 0.05;pos([2 4],1) = 0.53;
pos([1 2],2) = 0.52;pos([3 4],2) = 0.04;
效果如下:
在这里插入图片描述

3 × 2 三行两列的子图
pos6 = zeros(6,4); % 3行2列 绘图 % [left bottom width height]
pos6(:,3) = 0.44;pos6(:,4) = 0.30;
pos6([5 6],2) = 0.03;pos6([3 4],2) = 0.35;pos6([1 2],2) = 0.67;
pos6([1 3 5],1) = 0.03;pos6([2 4 6],1) = 0.53;
figure()
subplot(‘position’,pos6(1,:))
subplot(‘position’,pos6(2,:))
subplot(‘position’,pos6(3,:))
subplot(‘position’,pos6(4,:))
subplot(‘position’,pos6(5,:))
subplot(‘position’,pos6(6,:))
在这里插入图片描述
4 × 2 4行2列

pos42 = zeros(8,4);
pos42(:,3) = 0.44;pos42(:,4) = 0.22;
pos42([7 8],2) = 0.03;pos42([5 6],2) = 0.27;pos42([3 4],2) = 0.51;pos42([1 2],2) = 0.75;
pos42([1 3 5 7],1) = 0.03;pos42([2 4 6 8],1) = 0.53;

figure()
subplot(‘position’,pos42(1,:))
subplot(‘position’,pos42(2,:))
subplot(‘position’,pos42(3,:))
subplot(‘position’,pos42(4,:))
subplot(‘position’,pos42(5,:))
subplot(‘position’,pos42(6,:))
subplot(‘position’,pos42(7,:))
subplot(‘position’,pos42(8,:))
在这里插入图片描述

  • 6
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值