图形窗口的分割
子图:同一图形窗口中的不同坐标系下的图形称为子图。
Subplot函数: subplot(m,n,p)
其中,m和n指定将图形窗口分成m×n个绘图区,p指定当前活动区。
subplot(2,2,1);
x=linspace(0,2*pi,60);
y=sin(x);
plot(x,y);
title('sin(x)');
axis([0,2*pi,-1,1]);
subplot(2,2,2);
x=linspace(0,2*pi,60);
y=cos(x);
plot(x,y);
title('cos(x)');
axis([0,2*pi,-1,1]);
![a60360e05466cc31ee6eebaded0039b4.png](https://i-blog.csdnimg.cn/blog_migrate/8293030a90f1874668e70e522637fc16.jpeg)
重复训练,熟练掌握:
x=linspace(0,2*pi,60);
subplot(2,2,1);
plot(x,sin(x)-1);
title('sin(x)-1');
axis([0,2*pi,-2,0])
subplot(2,1,2);
plot(x,cos(x)+1);
title('cos(x)+1');
axis([0,2*pi,0,2]);
subplot(4,4,3);
plot(x,tan(x));
title('tan(x)');
axis([0,2*pi,-40,40]);
subplot(4,4,8);
plot(x,cot(x));
title('cot(x)');
axis([0,2*pi,-35,35]);
![b765cd727b69df6520d4cf43654af974.png](https://i-blog.csdnimg.cn/blog_migrate/1fae7b0d5f86eed87df372dafba572af.jpeg)
其他坐标系下的二维曲线图:
(1)对数坐标图:
semilogx(x1,y1,选项1,x2,y2,选项2,……)
semilogy(x1,y1,选项1,x2,y2,选项2,……)
loglog (x1,y1,选项1,x2,y2,选项2,……)
例一:绘制 的直角线性坐标图和三种对数坐标图。
x=0:0.1:10;
y=1./x;
subplot(2,2,1);
plot(x,y);
title('plot(x,y)');
subplot(2,2,2);
semilogx(x,y)
title('semilogx(x,y)');
grid on
subplot(2,2,3);
semilogy(x,y);
title('semilogy(x,y)');
grid on
subplot(2,2,4);
loglog(x,y);
title('loglog(x,y)');
grid on
![ef40780564f5cc821dc6c5fcf6069467.png](https://i-blog.csdnimg.cn/blog_migrate/f794386ac559195be5e71d4cadf7f96e.jpeg)
(2)极坐标图
polar(theta,rho,选项)
其中,theta为极角,rho为极径,选项内容与plot函数相同。
t=0:pi/100:2*pi;
r=1-sin(t);
subplot(1,2,1);
polar(t,r);
subplot(1,2,2);
t1=t-pi/2;
r1=1-sin(t1);
polar(t,r1)
![d46e92a70df7e3a70b435e62ebcd0109.png](https://i-blog.csdnimg.cn/blog_migrate/8808ed7c4443fe7a92b2ebe201fa003f.jpeg)