第 5 章 数据和函数的可视化
5.1
5.1.1
引导
离散数据和离散函数的可视化
【例5.1-1】
n=(-10:10)'; y=abs(n);
plot(n,y,'r.','MarkerSize',20) axis equal
grid on xlabel('n') 121086420-2-10-8-6-4-20n246810图 5.1-1 离散函数的可视化
5.1.2
【例5.1-2】
连续函数的可视化
t1=(0:11)/11*pi; t2=(0:400)/400*pi; t3=(0:50)/50*pi; y1=sin(t1).*sin(9*t1); y2=sin(t2).*sin(9*t2); y3=sin(t3).*sin(9*t3);
subplot(2,2,1),plot(t1,y1,'r.')
1
axis([0,pi,-1,1]),title('(1)点过少的离散图形') subplot(2,2,2),plot(t1,y1,t1,y1,'r.')
axis([0,pi,-1,1]),title('(2)点过少的连续图形') subplot(2,2,3),plot(t2,y2,'r.')
axis([0,pi,-1,1]),title('(3)点密集的离散图形') subplot(2,2,4),plot(t3,y3)
axis([0,pi,-1,1]),title('(4)点足够的连续图形') (1)点过少的离散图形10.50-0.5-1012310.50-0.5-10123(2)点过少的连续图形(3)点密集的离散图形10.50-0.5-1012310.50-0.5-10(4)点足够的连续图形123图 5.1-2 连续函数的图形表现方法
【例5.1-3】
N=9;
t=0:2*pi/N:2*pi;
x=sin(t);y=cos(t); tt=reshape(t,2,(N+1)/2); tt=flipud(tt); tt=tt(:); xx=sin(tt);yy=cos(tt);
subplot(1,2,1),plot(x,y)
title('(1) 正常排序图形'),axis equal off,shg subplot(1,2,2),plot(xx,yy)
title('(2) 非正常排序图形'),axis equal off,shg
2
(1) 正常排序图形(2) 非正常排序图形图 5.1-3 自变量排列次序对连续曲线图形的影响
5.2
5.2.1
二维曲线和图形
二维曲线绘制的基本指令plot
【例5.2-1】
clf t=(0:pi/50:2*pi)'; k=0.4:0.1:1; Y=cos(t)*k; subplot(1,2,1)
plot(t,Y,'LineWidth',1.5) title('By plot(t,Y)') xlabel('t') subplot(1,2,2)
plot(Y,'LineWidth',1.5) title('By plot(Y)')
xlabel('row subscript of Y')
3
By plot(t,Y)10.80.60.40.20-0.2-0.4-0.6-0.8-1024t6810.80.60.40.20-0.2-0.4-0.6-0.8-10By plot(Y)50100row subscript of Y150图 5.2-1 plot(t,Y)与plot(Y)所绘曲线的区别
【例5.2-2】
t=(0:pi/100:pi)'; y1=sin(t)*[1,-1]; y2=sin(t).*sin(9*t);
t3=pi*(0:9)/9; y3=sin(t3).*sin(9*t3); plot(t,y1,'r:',t,y2,'-bo') hold on
plot(t3,y3,'s','MarkerSize',10,'MarkerEdgeColor',[0,1,0],'MarkerFaceColor',[1,0.8,0]) axis([0,pi,-1,1]) hold off
%plot(t,y1,'r:',t,y2,'-bo',t3,y3,'s','MarkerSize',10,'MarkerEdgeColor',[0,1,0],'MarkerFaceColor',[1,0.8,0])
4
10.80.60.40.20-0.2-0.4-0.6-0.8-100.511.522.53图5.2-2 属性控制下所绘曲线
5.2.2
【例5.2-3】
坐标控制和图形标识
t=0:2*pi/99:2*pi;
x=1.15*cos(t);y=3.25*sin(t);
subplot(2,3,1),plot(x,y),axis normal,grid on, title('Normal and Grid on')
subplot(2,3,2),plot(x,y),axis equal,grid on,title('Equal') subplot(2,3,3),plot(x,y),axis square,grid on,title('Square')
subplot(2,3,4),plot(x,y),axis image,box off,title('Image and Box off') subplot(2,3,5),plot(x,y),axis image fill,box off title('Image and Fill')
subplot(2,3,6),plot(x,y),axis tight,box off,title('Tight')
5