1.线图
- plot函数用来创建x和y值的简单线图
x = 0:0.05:30; %0为起点,30为终点,0.05为间隔
y = sin(x);
plot(x,y,'LineWidth',2) %以x为横坐标,以y为纵坐标;后面为调粗细
xlabel("横轴标题")
ylabel("纵轴标题")
grid on %显示网格
axis([0 20 -1.5 1.5]) %设置横纵坐标范围;横坐标:0-20;纵坐标:-1.5-1.5
- 多组函数显示在同一张图
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
axis([0 20 -1.5 1.5]) %设置横纵坐标范围;横坐标:0-20;纵坐标:-1.5-1.5
2.条形图
- bar函数创建直条形图
- barh函数创建水平条形图
t = -3:0.09:3;
p = exp(-t.*t); %e^(-t*t) ; 其中.*为点乘
bar(t,p)
barh(t,p)
3.极坐标图
- polarplot函数画极坐标图
theta = 0:0.01:2*pi;
% abs求绝对值或者复数的模
radi = abs(sin(7*theta).*cos(10*theta)); %极坐标里面r为正;其中.*是因为sin,cos都是以矩阵存在
polarplot(theta,radi) %(弧度,半径)
4.散点图
- scatter函数绘制x,y的散点图
height = randn(1000,1); %randn:1000行1列的随机元素矩阵,但符合正态分布
weight = randn(1000,1);
scatter(height,weight)
xlabel("height")
ylabel("weight")