进阶绘图

Logarithm Plots:

>> x=logspace(-1,1,100);
>> y=x.^2;
>> subplot(2,2,1);
plot(x,y);
>> title('Plot');
>> subplot(2,2,2);
>> semilogx(x,y);
>> title('Semilogx');
>> subplot(2,2,3);
>> semilogy(x,y);
>> title('Semilogy');
>> subplot(2,2,4);
>> loglog(x,y);
>> title('Title');

在这里插入图片描述
XGrid:

set(gca,'XGrid','on');

在这里插入图片描述
plotyy():
y = a ∗ e − b x ∗ s i n ( c x ) y=a*e^{-bx}*sin(cx) y=aebxsin(cx)

x=0:0.01:20;
y1=200*exp(-0.05*x).*sin(x);
y2=0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2]=plotyy(x,y1,x,y2);
set(get(AX(1),'YLabel'),'String','Left Y-axis');
set(get(AX(2),'YLabel'),'String','Right Y-label');
title('Labeling plotyy');
set(H1,'LineStyle','--');
set(H2,'LineStyle',':');

在这里插入图片描述
Histogram:

y=randn(1,1000);
subplot(2,1,1);
hist(y,10);
title('Bins=10');
subplot(2,1,2);
hist(y,50);
title('Bins=50');

在这里插入图片描述
Bar Chart:

>> x=[1 2 3 4 6];
>> clear x
>> x=[1 2 5 4 8];
>> y=[x;1:5];
>> subplot(1,3,1);
>> bar(x);
>> title('A bargraph of vector x');
>> subplot(1,3,2);bar(y);title('A bargraph of vector y');
>> subplot(1,3,3);bar3(y);title('A 3D bargraph');

在这里插入图片描述
Stacked and Horizontial Bar Charts:

>> x=[1 2 5 4 8];
>> y=[x;1:5];
>> subplot(1,2,1);
>> bar(y,'stacked');
>> title('Stacked');
>> subplot(1,2,2);
>> barh(y);
>> title('Horizontal');

在这里插入图片描述
Pie Charts:

>> a=[10 5 20 30];;
>> subplot(1,3,1);
>> pie(a);
>> subplot(1,3,2);
>> pie(a,[0,0,0,1]);
>> subplot(1,3,3);
>> pie3(a,[0,0,0,1]);

在这里插入图片描述
Exercise:

 pie(a,[1,1,1,1]);

在这里插入图片描述
Polar Chart:

>> x=1:100;theta=x/10;r=log10(x);
>> subplot(1,4,1);polar(theta,r);
>> theta=linspace(0,2*pi);r=cos(4*theta);
>> subplot(1,4,2);polar(theta,r);
>> theta=linspace(0,2*pi,6);r=ones(1,length(theta));
>> subplot(1,4,3);polar(theta,r);
>> theta=linspace(0,2*pi);r=1-sin(theta);
>> subplot(1,4,4);polar(theta,r);

在这里插入图片描述
Exercise:

>> theta=linspace(0,2*pi,7);
>> r=ones(1,length(theta));
>> polar(theta,r);

在这里插入图片描述
Stairs and Stem Charts:

>> x=linspace(0,4*pi,40);
>> y=sin(x);
>> subplot(1,2,1);
>> stairs(y);
>> subplot(1,2,2);
>> stem(y);

在这里插入图片描述
Exercise:

>> x=linspace(0,10,50);
>> y=sin(pi*x.^2/4);
>> stem(x,y);
>> stem(x,y);
>> plot(x,y);
>> hold on
>> stem(x,y);

在这里插入图片描述
Boxplot and Error Bar:

>> load carsmall
>> boxplot(MPG,Origin);

在这里插入图片描述

>> load carsmall
>> boxplot(MPG,Origin);
>> x=0:pi/10:pi;
>> y=sin(x);
>> e=std(y)*ones(size(x));
>> errorbar(x,y,e);

在这里插入图片描述
fill():

>> t=(1:2:15)'*pi/8;
>> 
>> x=sin(t);
>> y=cos(t);
>> fill(x,y,'r');
>> axis square off;
>> text(0,0,'STOP','Color','w','FontSize',50,'FontWeight','bold','HorizontalAlignment','center');

在这里插入图片描述
Color Space:

>> h(1).FaceColor='y';
>> h(2).FaceColor='black';
>> h(3).FaceColor='r';

在这里插入图片描述
Visualizing Data as An Image :imagesc()

>> [x,y]=meshgrid(-3:.2:3,-3:.2:3);
>> z=x.^2+x.*y+y.^2;surf(x,y,z);box on;

在这里插入图片描述

>> [x,y]=meshgrid(-3:.2:3,-3:.2:3);
>> z=x.^2+x,*y+y.^2;surf(x,y,z);box on;
>> z=x.^2+x.*y+y.^2;surf(x,y,z);box on;
>> set(gca,'FontSize',16);zlabel('z');
>> xlim([-4,4]);xlabel('x');ylim([-4,4]);ylabel('y');
>> imagesc(z);
>> axis square;
>> xlabel('x');
>> ylabel('y');

在这里插入图片描述
Color Bar and Scheme:

Volorbar;

在这里插入图片描述

colormap(hot);

在这里插入图片描述

colormap(cool);

在这里插入图片描述

colormap(gray);

在这里插入图片描述
Build-in Colormaps:
在这里插入图片描述
在这里插入图片描述
Exercise:

>> x=[1:10;3:12;5:14];
>> imagesc(x);
>> colorbar;

在这里插入图片描述

>> x=0:0.1:3*pi; z1=sin(x); z2=sin(2*x); z3=sin(3*x);
>> y1=zeros(size(x)); y3=ones(size(x)); y2=y3./2;
>> plot3(x,y1,z1,'r',x,y2,z2,'b',x,y3,z3,'g');grid on;
>> xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');

在这里插入图片描述
More 3D Line Plots:

>> t=0:pi/50:10*pi;
>> plot3(sin(t),cos(t),t)
>> grid on;
>> axis square;

在这里插入图片描述
Principles for 3D Surface Plots:

turns=40*pi;
t=linspace(0,turns,4000);
x=cos(t).*(turns-t)./turns;
y=sin(t).*(turns-t)./turns;
z=t./turns;
plot3(x,y,z);grid on;

在这里插入图片描述
Principles for 3D Surface Plots:

>> x=-2:1:2;
>> y=-2:1:2;
>> [x,y]=meshgrid(x,y);

在这里插入图片描述
Surface Plots :mesh() and surf():

>> x=-3.5:0.2:3.5;y=-3.5:0.2:3.5;
>> [X,Y]=meshgrid(x,y);
>> Z=X.*exp(-X.^2-Y.^2);
>> subplot(1,2,1);mesh(X,Y,Z)
>> subplot(1,2,2);surf(X,Y,Z)

在这里插入图片描述
Contour():

>> subplot(2,1,1);mesh(X,Y,Z);axis square;
>> subplot(2,1,2);contour(X,Y,Z);axis square;

在这里插入图片描述
Various Contour Plots:

>> subplot(1,3,1);contour(Z,[-.45:.05:.45]);axis square;
>> subplot(1,3,2);[C,h]=contour(Z);clabel(C,h);axis square;
>> subplot(1,3,3);contourf(Z);axis square;

在这里插入图片描述
Exercise:

[C,h]=contourf(Z,[-.5:.05:.5]);clabel(C,h);axis square;

在这里插入图片描述
meshc()和surfc():

>> x=-3.5:0.2:3.5;
>> y=-3.5:0.2:3.5;
>> [X,Y]=meshgrid(x,y);
>> Z=X.*exp(-X.^2-Y.^2);
>> subplot(1,2,1);meshc(X,Y,Z);
>> subplot(1,2,2);surfc(X,Y,Z);

在这里插入图片描述
View angle:view()

>> sphere(50);
>> shading flat;
>> light('Position',[1 3 2]);
>> light('Position',[-3 -1 3]);
>> material shiny;
>> axis vis3d off;
>> set(gcf,'Color',[1 1 1]);
>> view(-45,20);

在这里插入图片描述
Light :light():

>> [X,Y,Z]=sphere(64);
>> h=surf(X,Y,Z);
>> axis square vis3d off;
>> reds=zeros(256,3);
>> reds(:,1)=(0:256.-1)/255
>> colormap(reds);
>> shading interp;
>> lighting phong;
>> set(h,'AmbientStrength',0.75,'DiffuseStrength',0.5);
>> L1=light('Position',[-1,-1,-1]);
>> set(L1,'Position',[-1,-1,-1]);

在这里插入图片描述

>> set(L1,'Position',[-1,-1,1]);
>> light('Position',[-1,-1,-1]);

在这里插入图片描述
patch():
A graphical object containing polygons:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值