MATLAB 绘图函数参考

MATLAB subplot 函数把图形窗口分成 m×n 个子图,并在指定格子中绘图。

语法

subplot(m, n, p)

m 行、n 列,p 是当前位置(按行优先:1 左上、2 右上、3 左下、4 右下)。

示例

1×2 并排:

x = 0:0.01:2*pi;
subplot(1, 2, 1)
plot(x, sin(x)), title('sin')

subplot(1, 2, 2)
plot(x, cos(x)), title('cos')

2×2 布局:

subplot(2, 2, 1), plot(x, x.^2/20), title('x^2')
subplot(2, 2, 2), plot(x, exp(-x)), title('e^-x')
subplot(2, 2, 3), plot(x, sin(x)),  title('sin')
subplot(2, 2, 4), plot(x, cos(x)),  title('cos')

注意事项

  • 每个子图是独立坐标系,可各自加 title/label/axis;
  • 2×2 编号别搞错:3 在左下、4 在右下。