matlab绘图 subplot函数使用方法 |
您所在的位置:网站首页 › cossin-cossin的m次方是 › matlab绘图 subplot函数使用方法 |
在平铺位置创建坐标轴 语法 ①subplot(m,n,p) subplot(m,n,p) 将当前图形划分为 m×n 网格,并在 p 指定的位置创建坐标轴。MATLAB® 按行号对子图位置进行编号。第一个子图是第一行的第一列,第二个子图是第一行的第二列,依此类推。如果指定的位置已存在坐标轴,则此命令会将该坐标轴设为当前坐标轴。 ②subplot(m,n,p,‘replace’) subplot(m,n,p,‘replace’) 删除位置 p 处的现有坐标轴并创建新坐标轴。 ③subplot(m,n,p,‘align’) subplot(m,n,p,‘align’) 创建新坐标轴,以便对齐图框。此选项为默认行为。 ④subplot(m,n,p,ax) subplot(m,n,p,ax) 将现有坐标轴 ax 转换为同一图形中的子图。 ⑤subplot(‘Position’,pos) subplot(‘Position’,pos) 在 pos 指定的自定义位置创建坐标轴。使用此选项可定位未与网格位置对齐的子图。指定 pos 作为 [left bottom width height] 形式的四元素矢量。如果新坐标轴与现有坐标轴重叠,新坐标轴将替换现有坐标轴。 ⑥subplot(___,Name,Value) subplot(___,Name,Value) 使用一个或多个名称-值对组参数修改坐标轴属性。有关属性列表,请参阅 Axes 属性。在所有其他输入参数之后设置坐标轴属性。 ⑦ax = subplot(___) ax = subplot(___) 返回创建的 Axes 对象。以后可以使用 ax 修改坐标轴。有关属性列表,请参阅 Axes 属性。 ⑧subplot(ax) subplot(ax) 将 ax 指定的坐标轴设为父图的当前坐标轴。如果父图尚不是当前图形,此选项不会使父图成为当前图形。 示例 (1)上部和下部子图 创建带有两个堆叠子图的图形。在每个子图上绘制一条正弦波。 subplot(2,1,1); x = linspace(0,10); y1 = sin(x); plot(x,y1) title('Subplot 1: sin(x)') subplot(2,1,2); y1 = sin(5*x); plot(x,y2) title('Subplot 2: sin(5x)')
情况一:图形编号在各个子图的上方 subplot(2,2,1) x = linspace(0,10); y1 = sin(x); plot(x,y1) title('Subplot 1: sin(x)') subplot(2,2,2) y2 = sin(2*x); plot(x,y2) title('Subplot 2: sin(2x)') subplot(2,2,3) y3 = sin(4*x); plot(x,y3) title('Subplot 3: sin(4x)') subplot(2,2,4) y4 = sin(8*x); plot(x,y4) title('Subplot 4: sin(8x)')情况二:图形编号在各个子图的下方 subplot(2,2,1) x = linspace(0,10); y1 = sin(x); plot(x,y1) title('(a) sin(x)', 'Units', 'normalized', 'Position', [0.5, -0.3, 0]) subplot(2,2,2) y2 = sin(2*x); plot(x,y2) title('(b) sin(2x)', 'Units', 'normalized', 'Position', [0.5, -0.3, 0]) subplot(2,2,3) y3 = sin(4*x); plot(x,y3) title('(c) sin(4x)', 'Units', 'normalized', 'Position', [0.5, -0.3, 0]) subplot(2,2,4) y4 = sin(8*x); plot(x,y4) title('(d) sin(8x)', 'Units', 'normalized', 'Position', [0.5, -0.3, 0]')(3)大小不同的子图 创建一个包含三个子图的图形。在图形的上半部分创建两个子图,并在图形的下半部分创建第三个子图。在每个子图上添加标题。 subplot(2,2,1); x = linspace(-3.8,3.8); y_cos = cos(x); plot(x,y_cos); title('Subplot 1: Cosine') subplot(2,2,2); y_poly = 1 - x.^2./2 + x.^4./24; plot(x,y_poly,'g'); title('Subplot 2: Polynomial') subplot(2,2,[3,4]); plot(x,y_cos,'b',x,y_poly,'g'); title('Subplot 3 and 4: Both')
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |