x=0:0.01:pi;
y1=sin(x);
y2=2*sin(x);
y3=3*sin(x);
plot(x,y1,':')
hold on;
plot(x,y2,'--')
hold on
plot(x,y3,'p')
plot(x,y1,'-',x,y2,'x',x,y3,'o');
%%颜色控制
plot(x,y1,'r');
plot(x,y2,'b');
plot(x,y3,'k');
plot(x,y1,'r',x,y2,'b',x,y3,'k')
%%线宽控制
plot(x,y1);
plot(x,y2,'LineWidth',2)
plot(x,y3,'LineWidth',4)
plot(x,y1,'LineWidth',1);hold on;
plot(x,y2,'LineWidth',2);hold on;
plot(x,y3,'LineWidth',4);hold on;
set(0,'DefaultAxesLineStyleOrder','--')
plot(x,y1)
%%实例
x=0:0.01:4*pi;
y1=exp(-x/3).*sin(3*x);
y2=exp(-x/3);
y3=-exp(-x/3);
plot(x,y1,'LineWidth',3);
hold on;
plot(x,y2,'--r','LineWidth',2);
hold on;
plot(x,y3,'-.m','LineWidth',1);
%%子图的绘制
x=0:0.01:pi/2;
y1=sin(x);
y2=cos(x);
y3=tan(x);
y4=cot(x);
subplot(2,2,1);
plot(x,y1);
subplot(2,2,2);
plot(x,y2);
subplot(2,2,3);
plot(x,y3);
subplot(2,2,4);
plot(x,y4);
%%双y轴图形的绘制
x=0:0.01:20;
y1=100*exp(-0.05*x).*sin(x);
y2=exp(-0.5*x).*sin(10*x);
plot(x,y1,x,y2); %%普通重叠图
hold on;
plotyy(x,y1,x,y2); %%双y轴图
%%绘图网格
x=-pi:0.01:pi;
y=sin(x);
plot(x,y);
grid on
x=-pi:0.01:pi;
y=sin(x);
grid on;
hold on;
plot(x,y)
%%坐标轴的显示
x=-pi:0.01:pi;
y=sin(x);
plot(x,y);
box off
%%绘制二维图形范围
x=0:0.01:pi/2;
y=tan(x);
plot(x,y)
axis([0 pi/2 0 10])
%%坐标轴控制
x=-pi:0.01:pi;
y1=sin(x);
y2=2*cos(x);
plot(x,y1);
axis manual
hold on;
plot(x,y2,'LineWidth',3);
%%输入一个参数绘制图形
%标准
t=0:0.01:2*pi;
x=sin(t);
y=cos(t);
plot(x,y);
%方形参数坐标轴
t=0:0.01:2*pi;
x=sin(t);
y=cos(t);
plot(x,y);
axis square
%等刻度坐标轴
t=0:0.01:2*pi;
x=sin(t);
y=cos(t);
plot(x,y);
axis equal
%%坐标轴标准
x=0:0.01:2*pi;
y=sin(x);
plot(x,y);
xlabel('x(0-pi/2)/\alpha');
ylabel('y=sin(x)');
title('正弦函数');
%%文本标注
x=0:0.01:2*pi;
y=sin(x);
plot(x,y);
text(pi,0,'x=pi,y=0');
hold on;
plot(pi,0,'*')
gtext('正弦曲线')
%%图例标注
x=-pi:0.01:pi;
y=sin(x);
y1=cos(x);
plot(x,y,'-ro',x,y1,'-.b');
legend('sin','cos',1);
%%双y轴图标注
x=0:0.01:20;
y1=100*exp(-0.05*x).*sin(x);
y2=exp(-0.5*x).*sin(10*x);
[ax,h1,h2]=plotyy(x,y1,x,y2);
xlabel('x(0~20)');
ylabel('left yaxis');
axes(ax(2));
ylabel('right yaxis');
set(h1,'linestyle','--');
title('双y轴图')
%%实例
x1=-pi:0.01:pi;
x2=-pi:0.01:pi;
y1=sin(x1)+sin(2*x1)-cos(3*x1);
y2=2*sin(x2);
h1=plot(x1,y1)
hold on;
h2=plot(x2,y2);
xlabel('x(-pi~pi)');
ylabel('y');
title('曲线图')
legend('y1=sin(x1)+sin(2*x1)-cos(3*x1)','y2=2*sin(x)',2);
%%交互式命令进行绘制曲线
axis([0 15 0 15]);
grid on;
hold on;
title('通过点击鼠标选取点');
xy=[];
n=0;
disp('提示:单击左键选择点,单击右键结束选择');
but=1;
while but==1
[xi,yi,but]=ginput(1);
plot(xi,yi,'bp');
n=n+1;
xy(:,n)=[xi;yi];
end
t=1:n;
ts=1:0.1:n;
xys=spline(t,xy,ts);
plot(xys(1,:),xys(2,:),'r-','LineWidth',2);
hold off
%%函数绘图 easy 绘图命令
subplot(2,1,1);
fplot(@humps,[-0.5,3]);
title('figure 1:humps');
grid on;
subplot(2,1,2);
f_h=@(x) sin(x)/x;
fplot(f_h,[-10,10]);
title('figure 2 sin(x)/x');
grid on;
syms t
y=exp(-2*t/3)*sin(1+2*t);
ezplot(y,[pi,3*pi]);
grid on;
ezpolar('1+cos(t)');