使用 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,:))