Matlab常用函数——plotyy函数
的有关信息介绍如下:方法/步骤 1 plotyy函数,用于在一个图中绘制多条2D图形的一个非常常用的函数。有多种格式,下面将给出一般的使用规范。
2 用两个y轴绘制两个图像
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure % new figure
plotyy(x,y1,x,y2)
3 增加标题和y轴标签
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure % new
figure[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
title('Multiple Decay Rates')
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay') % left y-axisylabel(hAx(2),'Fast Decay') % right y-axis
4 更改线型
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
hLine1.LineStyle = '--';
hLine2.LineStyle = ':';
5 将两种不同的线型绘制在一起
x = 0:0.1:10;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure
plotyy(x,y1,x,y2,'plot','stem')
6 使用带有两个y轴的图绘制三组数据。 绘制与左侧y轴相关的一组数据。 通过使用两列矩阵绘制与右侧y轴相关联的两组数据。
x = linspace(0,10);
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
y3 = 0.2*exp(-0.5*x).*sin(10*x);
figure
[hAx,hLine1,hLine2] = plotyy(x,y1,[x',x'],[y2',y3']);
END