MATLAB之绘图可视化

绘图可视化:

1.简单绘图:

plot函数:
参数设置:
(1) (x,y): 以x为横坐标,y为纵坐标,按照(x,y)的顺序绘图。
(2)(y): y为以为实数数组,以1:n为横坐标,y为纵坐标绘图(n为y的长度)
(3)(X, Y, LineSpec): 用户指定的绘图样式
在这里插入图片描述

sin cos 图像(间隔0.02):

t=0.1:0.02:2*pi;
figure;
plot(t,sin(t),‘r:’);
hold on;
plot(t,cos(t),‘b:’);
xlabel(‘x’);
ylabel(‘y’);
title(‘plot’);

在这里插入图片描述

四行四列矩阵绘图:

A=[2 5 9 6 ; 5 8 6 3 ; 8 4 6 2; 8 9 3 5]
figure;
plot(A);

在这里插入图片描述

同时绘制多条曲线:

x=0:0.01:16;
y=sin(x);
z=cos(x);
figure;
plot(x,y,‘r:*’,x,z,‘g-.v’);

在这里插入图片描述

2.子图绘制和坐标轴控制:

(1)子图绘制:

subplot(m,n,p)函数:
m表示是图排成m行,n表示图排成n列,p表示图所在的位置。例如p=1表示从左到右从上到下的第一个位置。

x=0:0.01:16;
y=sin(x);
z=cos(x);
subplot(2,1,1);
plot(x,y,‘r–’);
subplot(2,1,2);
plot(x,z,‘g–’);

在这里插入图片描述

x=0:0.01:16;
y=sin(x);
z=cos(x);
s=tan(x);
subplot(2,2,1);
plot(x,y,‘r–’);
subplot(2,2,3);
plot(x,z,‘b–’);
subplot(2,2,[2,4]);
plot(x,z,‘g–’);

在这里插入图片描述

(2)坐标轴控制:

axis off: 取消坐标轴的显示。

axis( [xmin xmax ymin ymax] ):
可以设置当前坐标轴 x轴 和 y轴的限制范围。

axis( [xmin xmax ymin ymax zmin zmax cmin cmax] ) : 可以设置 x,y,z轴的限制范围和色差范围。

x=0:0.01:16;
y=sin(x);
plot(x,y,‘r–’);
axis([0 6 0 1]);

在这里插入图片描述

3.网格线和边框设置:

(1)网格线:

grid:
grid on; %显示网格线
grid off; %关闭网格线

x=0:0.01:16;
y=sin(x);
plot(x,y,‘r–’);
grid on;

在这里插入图片描述

(2)边框设置:

x=0:0.01:16;
y=sin(x);
plot(x,y,‘r–’);
box on;

在这里插入图片描述

4.中级技巧:

(1)拖拽

pan on;

x=0:0.01:16;
y=sin(x);
plot(x,y,‘r–’);
pan on;

(2)数据光标

datacursormode on;

x=0:0.01:16;
y=sin(x);
plot(x,y,‘r–’);
datacursormode on;

单击鼠标左键,即可获取数据点。
在这里插入图片描述

(3)极坐标绘图

polar(x,y,‘r–’); 参数:弧度、半径、线型

x=0:0.01:16;
y=sin(x);
polar(x,y,‘r–’);

在这里插入图片描述

(3)双Y轴绘图

plotyy(x,y,x,z);

x=0:0.01:16;
y=sin(x);
z=cos(x);
plotyy(x,y,x,z);

在这里插入图片描述

5.图例:

legend(‘sin(x)’,‘cos(x)’);

x=0:0.01:16;
y=sin(x);
z=cos(x);
plot(x,y,’-r’);
hold on;
plot(x,z,‘g-’);
axis([0 10 -1 1]);
legend(‘sin(x)’,‘cos(x)’);

在这里插入图片描述

6.文本标注

任意位置: gtext(‘y=sin(x)’);

x=0:0.01:16;
y=sin(x);
plot(x,y,’-r’);
gtext(‘y=sin(x)’);

在这里插入图片描述

7.各类二维图的绘制

(1) 直方图:

hist(x);

x=randn(100,1);
hist(x);

在这里插入图片描述

(2) 饼图:

pie(x,explode);
pie3();%可绘制三维饼图

x=[0.2 0.4 0.3];
subplot(121);
pie(x);
subplot(122);
y=[0.2 0.4 0.3 0.1];
explode([0 0 1 0]);
pie(y,explode);

在这里插入图片描述

(3) 散点图:

scatter(x,y);
scatter3();%可绘制三维散点图

x=[2 5 6 3 8 9 5 ];
y=[ 8 9 5 1 6 6 5 ];
scatter(x,y,[ ],[1 0 0],‘fill’);

在这里插入图片描述

8.三维图的绘制:

x=-10:0.1:10;
y=-10:0.1:10;
[X,Y]=meshgrid(x,y);
z=X.^ 2 + Y.^2;
surf(x,y,z);
colormap(‘cool’);
axis square;
view([55,75]);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘z’);

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

莫余

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值