ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

matlab高阶绘图

2021-02-14 19:57:49  阅读:252  来源: 互联网

标签:set axis 0.2 3.5 绘图 matlab pi 高阶 3D


这里写目录标题

二维绘图

对数图

semilogx()
semilogy()
loglog()

semilogx(x,y);//x轴是对数坐标
semilogy(x,y);
loglog(x,y);

两个y轴

plotyy()

[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-axis');
set(H1,'LineStyle','--');
set(H2,'LineStyle',':');

直方图

hist()

y=randn(1,1000);
hist(y,50);//Bins=50

条形图

bar()
bar3()
barh()

x1=[1,2,5,4,8];
x2=[...];
x3=[...];
X=[x1;x2;x3]
bar(x1);//无组别的条形图
bar(X);//有三个组
bar3(X);//3D
bar(X,'stacked');//堆在一起的条形图
barh(X);//horizontal,横过来的

饼图

pie()
pie3()

a=[10,5,20,30];
pie(a);
pie(a,[0,0,0,1]);//1对应的扇形被分隔出来
pie3(...);//3D

雷达图

polar()

theta=linspace(0,2*pi);
r=1-sin(theta);
polar(theta,r);

阶梯图

stairs()

x=linspace(0,4*pi,40);
y=sin(x);
stairs(x,y);

茎状图

stem()

x=linspace(0,4*pi,40);
y=sin(x);
stem(x,y);

箱形图

boxplot()

boxplot(x,y);

误差条

errorbar()

x=0:pi/10:pi;
y=sin(x);
err=std(y)*ones(size(x));//误差
errorbar(x,y,e);

填充颜色

fill()

theta=(1:2:15)'*pi/8;
x=sin(t);
y=cos(t);
fill(x,y,'r');//多边形内部填充红色
text(0,0,'STOP','Color','w','FontSize',80,'FontWeight','bold','HorizontalAlignment','center');

颜色空间

[R,G,B]三个通道,每个取值[0,1],0最浅,1最深。对应8位颜色的[0,255]。

将矩阵显示成图像

imagesc()

[x,y]=meshgrid(-3:0.2:3,-3:0.2:3);
z=x.^2+x.*y+y.^2;
imagesc(z);
colorbar;//颜色图例
colormap(hot);//采用什么配色方案

colormaps

colormap实际上是一个256*3的矩阵,例如:

myMap=ones(256,3);
colormap(myMap);

内置colormaps包括:内置colormaps

三维绘图

3D图线

plot3()

plot3(x1,y1,z1,'r',x2,y2,z2,'g',...);

例子:

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

3D表面

mesh()网格表面
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()
contourf()填充颜色

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);
contour(X,Y,Z);

或者

contour(Z,[-0.45:0.05:0.45]);//密集程度

或者

[C,h]=contour(Z);
clabel(C,h);//有数字

或者

contourf(Z);

3D表面+等高线投影

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);
meshc(X,Y,Z);

或者

surfc(X,Y,Z);

改变视角

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()

[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,'Color','g');//改变光的颜色

绘制多面体

patch()

v = [0 0 0; 1 0 0 ; 1 1 0; 0 1 0; 0.25 0.25 1; ...
	0.75 0.25 1; 0.75 0.75 1; 0.25 0.75 1];
f = [1 2 3 4; 5 6 7 8; 1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8];

subplot(1,2,1);
patch('Vertices', v, 'Faces', f, ... 'FaceVertexCData', hsv(6), 'FaceColor', 'flat');
view(3);
axis square tight;
grid on;

subplot(1,2,2);
patch('Vertices', v, 'Faces', f, ... 'FaceVertexCData', hsv(8), 'FaceColor', 'interp');
view(3);
axis square tight;
grid on;

一个应用

load cape;
X=conv2(ones(9,9)/81,cumsum(cumsum(randn(100,100)),2)); surf(X,'EdgeColor','none','EdgeLighting','Phong','FaceColor','interp');
colormap(map);
caxis([-10,300]);
grid off;
axis off;

标签:set,axis,0.2,3.5,绘图,matlab,pi,高阶,3D
来源: https://blog.csdn.net/m0_51834764/article/details/113803235

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有