matlab畫圖

y=[3,7,9,1,5,2,8];
subplot(1,2,1),plot(y,'linewidth',2),grid
x=[3,3,9;8,1,2;1,8,5;7,9,1];
subplot(1,2,2),plot(x),xlabel('x'),ylabel('y')
grid on
%極座標曲線
theta=0:0.1:8*pi;
polar(theta,cos(4*theta)+1/4)
%對數座標
x=0:0.1:2*pi;
y=sin(x);
semilogx(x,y);
grid on
%各種座標系中
theta=0:0.1:6*pi;
r=cos(theta/3)+1/9;
subplot(2,2,1),polar(theta,r);
subplot(2,2,2),plot(theta,r);
subplot(2,3,4),semilogx(theta,r);
subplot(2,3,5),semilogy(theta,r);
subplot(2,3,6),loglog(theta,r);
grid on
%雙y軸圖形
x=0:0.01:5;
y=exp(x);
plotyy(x,y,x,y,'semilogy','plot'),grid
grid on
%複數數據
t=0:0.1:2*pi;
x=sin(t);
y=cos(t);
z=x+i*y;
plot(t,z),grid
plot(z)
grid on
%二維圖形處理
x=(0:0.1:2*pi)';
y1=2*exp(-0.5*x)*[1,-1];
y2=2*exp(-0.5*x).*sin(2*pi*x);
x1=(0:12)/2;
y3=2*exp(-0.5*x1).*sin(2*pi*x1);
plot(x,y1,'g:',x,y2,'b--',x1,y3,'rp');
title('曲線及其包絡線');
xlabel('變量X');
ylabel('變量Y');
text(3.2,0.5,'包絡線');
text(0.5,0.5,'曲線y');
text(1.4,0.15,'離散數據點');
legend('包絡線','包絡線','曲線y','離散數據點')
clc
%座標控制
x=(0:0.1:2*pi)';
y1=2*exp(-0.5*x)*[1,-1];
y2=2*exp(-0.5*x).*sin(2*pi*x);
x1=(0:12)/2;
y3=2*exp(-0.5*x1).*sin(2*pi*x1);
plot(x,y1,'g:',x,y2,'b--',x1,y3,'rp');
plot(x,y1,'g:');
hold on;
plot(x,y2,'b--');
plot(x1,y3,'rp');
grid on;
box off;
hold off;
%圖形窗口的分割
t=(0:10:360)*pi/180;
y=sin(t);
subplot(2,1,1),plot(t,y);
subplot(2,2,3),stem(t,y);
subplot(2,2,4),polar(t,y);
y2=cos(t);y3=y2.*y2;
plot(t,y,'-or',t,y2,'-h',t,y3,'-xb');
xlabel('時間');
ylabel('幅值');
axis([-1,8,-1.2,1.2]);
%圖形設置
t=linspace(0,2*pi,60);
y1=sin(t);
y2=cos(t);
y3=y1.*y2;
h=figure(1);
stairs(t,y1);
h1=axes('pos',[0.2,0.2,0.6,0.4]);plot(t,y1);
h2=axes('pos',[0.1,0.1,0.8,0.1]);stem(t,y1);
h3=axes('pos',[0.5,0.5,0.4,0.4]);fill(t,y1,'g');
h4=axes('pos',[0.1,0.6,0.3,0.3]);plot(t,y1,'-',t,y2,':',t,y3,'o');
%在圖形中任意繪製座標系
set(h4,'pos',[0.1,0.1,0.4,0.4]);
set(h,'pos',[0,0,560,400]);
set(h3,'box','off');
set(h3,'xgrid','on');
set(h3,'gridlinestyle','-');
set(h3,'xdir','reverse');
set(h3,'xdir','normal');
ht3=get(h3,'title');
set(ht3,'string','澳洲人的迴旋鏢');
set(ht3,'rotation',-10);
set(ht3,'color',[244 29 249]/255);
%三維曲線圖
t=-pi:pi/200:8*pi;
h=figure(1);
set(h,'color',[1,1,1]);
subplot(1,2,1),plot3(cos(t),sin(t),t,'b-');
subplot(1,2,2),plot3(sin(t),cos(t),t,':');
%三維網格圖
[x,y]=meshgrid(-8:0.5:8,-10:0.5:10);
R=sqrt(x.^2+y.^2)+eps;
z=sin(R)./R;
mesh(x,y,z);
hidden off
%三維曲面
%繪製標準球面圖
subplot(2,2,1),sphere(4);
title('n=4'),axis equal;
subplot(2,2,2),sphere(6);
title('n=6'),axis equal;
subplot(2,2,3),sphere(20);
title('n=20'),axis equal;
subplot(2,2,4),sphere(50);
title('n=50'),axis equal;
%標準柱面圖
t=linspace(pi/2,3.5*pi,50);
R=cos(t)+2;
subplot(2,2,1),cylinder(R,3),title('n=3');
subplot(2,2,2),cylinder(R,6),title('n=6');
subplot(2,2,3),cylinder(R,20),title('n=20');
subplot(2,2,4),cylinder(R,50),title('n=50');
%圖形的平滑
[x,y]=meshgrid(-8:0.5:8,-10:0.5:10);
R=sqrt(x.^2+y.^2)+eps;
z=sin(R)./R;
surf(x,y,z);
colorbar;
shading flat
shading interp
[x,y]=meshgrid(-8:0.5:8,-10:0.5:10);
R=sqrt(x.^2+y.^2)+eps;
z=sin(R)./R;
surfc(x,y,z);
colorbar;
[x,y]=meshgrid(-8:0.5:8,-10:0.5:10);
R=sqrt(x.^2+y.^2)+eps;
z=sin(R)./R;
surfl(x,y,z);
colorbar;
%專用圖形
%條形圖
Y=[3,8,2;8,9,2;8,3,3;2,5,6;9,5,1];
subplot(1,2,1),bar(Y),title('二維條形圖');
subplot(1,2,2),bar3(Y),title('三維條形圖');
%直方圖
y1=randn(10000,1);
y2=rand(10000,1);
subplot(1,2,1);hist(y1,20);title('正態分佈');
subplot(1,2,2);hist(y2,10);title('均勻分佈');
theta=randn(1000,1);
theta=pi*theta/max(theta);
rose(theta);
%餅形圖
%二維餅形圖
cj=[80,95,70,40];
pie(cj,[0,0,1,0]);
%三維餅形圖
cj=[80,95,70,40];
pie3(cj,[0,0,1,0],{'語文28%','數學33%','外語25%','政治14%'});
%離散數據圖
x=linspace(0,2*pi,40);
a=sin(2*x);
b=cos(x);
stem(x,a+b);
hold on;
plot(x,a);hold on;
plot(x,b);hold on;
%三維離散數據圖
th=(0:127)/128*2*pi;
x=th.*cos(th);
y=th.*sin(th);
stem3(x,y,th,'fill');
view([-158 66]);
xlabel('X軸');ylabel('Y軸');zlabel('Z軸');
title('三維火柴桿圖');hold on;
plot3(x,y,th,'k');hold on;
%階梯圖
alpha=0.01;beta=0.5;t=0:10;
f=exp(-alpha*t).*sin(2*beta*t);stairs(t,f);
hold on;
plot(t,f,'--*');hold off;
label='函數e^{-(\alpha*t)}sin2\beta*t的階梯圖';
text(0.5,0.2,label,'FontSize',12);
xlabel('t=0:10','FontSize',14);
axis([0,10,-1.2,1.2]);
%等高線圖
[x,y,z]=peaks;
contour(x,y,z,15);
%三維等高圖
[x,y,z]=peaks;
contour3(x,y,z,20);
colormap(hsv)
%瀑布圖
waterfall(peaks);
axis tight;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章