Matlab数据可视化编程总结

Matlab数据可视化编程总结

Matlab上的可视化编程基本上分为三部分–绘制二维图形、绘制三维图形、GUIDE工具

绘制二维图形

二维绘图函数有很多,基本上分为线性图、条形图、填充图、矢量图、放射图、散射图六大类

plot函数–基本平面图形函数
plot函数的格式基本上是这样子的:
plot(x,y,…各种附加条件…)
列举几个例子
1.绘制sin(x)函数图像,区间为0-2π
x=0:pi/200:2*pi;
y=sin(x);
plot(x,y)
在这里插入图片描述

在区间0-2π内,绘制曲线Y=2e-0.5xcos(4πx)
octave:3> x=0:pi/200:2pi;
octave:4> y=2
exp(-0.5x).cos(4pix);
octave:5> plot(x,y)
在这里插入图片描述
在一个图像中随机两个随机曲线
octave:8> plot(rand(12,1))
octave:9> hold on
octave:10> plot(rand(12,1))
在这里插入图片描述
图形上的设置
1.线形和颜色
用不用的线形和颜色绘制cos 和sin函数
%g代表绿色o代表圆圈,b代表蓝色,-.代表点画线
x=0:pi/200:2pi;
a=sin(x);
b=cos(x);
plot(x,a,‘go’,x,b,‘b-.’)在这里插入图片描述
在-π,π上用任意颜色、样式绘制y=tan (sin(x)- sin (tan(x))
x=-pi:0.01:pi;
y=tan(sin(x))-sin(tan(x)) ;
plot(x,y,'b
’)
在这里插入图片描述
2.图形标记
title标题命名
xlabel 横轴命名
ylabel 纵轴命名

带正弦函数进行标记
x=0:pi/200:2*pi;
y=sin(x);
plot(x,y,‘go’)
title(‘sin’);
xlabel(‘x’);
ylabel(‘y’);
在这里插入图片描述
3.特殊图形
area函数
这个用面积来表示向量或者矩阵,用矩阵或者向量形成的曲线与X轴围城的面积

使用area函数绘制面域图,反映各因素最终结果贡献的份额
%建立M文件后输入
x=-2:2
x =

-2 -1 0 1 2

y=[3,5,2,4,1;3,4,5,2,1;5,4,3,2,5]
y =

3 5 2 4 1
3 4 5 2 1
5 4 3 2 5
sum=cumsum(y)
sum =

3    5    2    4    1
6    9    7    6    2

11 13 10 8 7
area(x’,y’,0)
legend(‘A’,‘B’,‘C’)
ans = -12.365
在这里插入图片描述
2.条图
x=-2:2;
y=[3,5,2,4,1;3,4,5,2,1;5,4,3,2,5];
subplot(1,2,1),bar(x’,y’,‘stacked’)
xlabel(‘x’),ylabel(‘y’),colormap(cool)
legend(‘因素A’,‘因素B’,‘因素C’)
subplot(1,2,2),barh(x’,y’,‘grouped’)
在这里插入图片描述

x=-2:2;
y=[3,5,2,4,1;3,4,5,2,1;5,4,3,2,5];
subplot(1,2,1),bar3(x’,y’,1)
xlabel(‘x’),ylabel(‘y’),zlabel(‘z’)
colormap(summer)
subplot(1,2,2),bar3h(x’,y’,‘grouped’)
ylabel('y’),zlabel(‘x’)
%这是三维的直方图,分别用bar3,bar3h表示垂直和水平横条,但是我这次用的是octave,似乎还没有开拓这个功能,所以跑不出来–The ‘bar3’ function is not yet implemented in Octave.

3.饼图
x = [1 3 0.5 2.5 2];
explode=[0 1 0 0 0]
pie(x,explode)
在这里插入图片描述

绘制三维图形

1.plot3函数–绘制三维曲线

t=0:pi/50:10pi;
plot3(sin(t),cos(t),t)
在这里插入图片描述
再来一个
t=0:pi/100:2
pi;
x=sin(t);
y=cos(t);
z=t.*sin(t).*cos(t);
plot3(x,y,z)
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘z’);
在这里插入图片描述

2.mesh函数–绘制三维网络图
mesh 和plot3不同,他可以绘制出在某一区间内的完整曲面

举个例子,在区间0-x-2pi,0-y-2pi,绘制出三维曲线y=sin (y)cos(x)
x=[0:0.15:2
pi];
y=[0:0.15:2*pi];
z=sin(y’)*cos(x);
mesh(x,y,z);
在这里插入图片描述

[x,y]=meshgrid(-3:1:3);
z=peaks(x,y);
meshc(x,y,z);
axis([-3 3 -3 3 -10 5])

在这里插入图片描述
3. 曲面等高线
[c,h]=contour(peaks(20),10);
colormap autumn
在这里插入图片描述

z=peaks;
[c,h]=contour(interp2(z,4));
text_handle=cabel(c,h);
set(text_handle,‘BackgroundColor’,[1 1 .6],…‘Edgecolor’,[.7 .7 .7])
在这里插入图片描述
4.contour3 函数–三维等高线

[x,y]=meshgrid([-4:.2:4]);
z=x.*exp(-x.^2-y .^2);
contour3(x,y,z,30)
在这里插入图片描述
[x,y]=meshgrid([-2:.25:2]);
z=x.*exp(-x.^2-y .^2);
contour3(x,y,z,30)
surface(x,y,z,‘EdgeColor’,[.8 .8 .8].‘FaceColor’,‘none’)

在这里插入图片描述
5.sphere函数–绘制球体

figure
[x,y,z]=sphere;
surf(x,y,z)
hold on
surf(x+3,y-2,z)
在这里插入图片描述
surf函数–着色的三维曲面

[x,y,z]=peaks(30);
surfc(x,y,z)
colormap hsv
在这里插入图片描述

GUIDE工具

由于这次我是用线上的octave完成的,所以GUIDE这部分后期找机会我再来补充了

参考文献
MATLAB科学计算与数据统计应用–赵彬等著
MATLAB入门到实践--谢龙汉、蔡思琪著

猜你喜欢

转载自blog.csdn.net/weixin_47567401/article/details/113382696
今日推荐