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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值