Matlab绘图(二维)

1、plot

1)、plot(x) —— 缺省自变量绘图格式,x为向量, 以x元素值为纵坐标,以相应元素下标为横坐标绘图


2)、plot(x,y) —— 基本格式,以y(x)的函数关系作出直角坐标图,如果y为n×m的矩阵,则以x 为自变量,作出m条曲线
3)、plot(x1,y1,x2,y2) —— 多条曲线绘图格式

4)、plot(x,y,’s’) —— 开关格式,开关量字符串s设定曲线颜色和绘图方式,使用颜色字符串的前1~3个字母,如yellow—yel表示等。或plot(x1,y1,’s1’,x2,y2,’s2’,…)

                              

plot(t,y,'r-',t,y1,'g:',t,y2,'b*')

                           

2、子图:subplot

3、多窗口绘图:figure

figure(n) —— 创建窗口函数,n为窗
口顺序号。
t=0:pi/100:2*pi;
y=sin(t);y1=sin(t+0.25);y2=sin(t+0.5);
plot(t,y) —— 自动出现第一个窗口
figure(2)
plot(t,y1) —— 在第二窗口绘图
figure(3)
plot(t,y2) ——在第三窗口绘图

4、给图加注释

将标题、坐标轴标记、网格线及文字注
释加注到图形上,这些函数为:
title —— 给图形加标题
xlable —— 给x轴加标注
ylable —— 给y轴加标注
text —— 在图形指定位置加标注
gtext —— 将标注加到图形任意位置
grid on(off) —— 打开、关闭坐标网格线
legend —— 添加图例
axis —— 控制坐标轴的刻度

例:t=0:0.1:10
y1=sin(t);y2=cos(t);plot(t,y1,'r',t,y2,'b--');
x=[1.7*pi;1.6*pi];
y=[-0.3;0.8];
s=['sin(t)';'cos(t)'];
text(x,y,s);
title('正弦和余弦曲线');
legend('正弦','余弦')
xlabel('时间t'),ylabel('正弦、余弦')
grid
axis square

axis的用法还有:
axis([xmin xmax ymin ymax]) —— 用行向量中给出的值设定坐标轴的最大和最小值。
如axis ([-2 2 0 5])
axis(equal) —— 将两坐标轴设为相等
axis on(off) —— 显示和关闭坐标轴的标记、标志
axis auto —— 将坐标轴设置返回自动缺省值

5、其他绘图

bar –––– 绘制直方图
polar –––– 绘制极坐标图
hist –––– 绘制统计直方图
stairs –––– 绘制阶梯图
stem –––– 绘制火柴杆图
rose –––– 绘制统计扇形图
comet –––– 绘制彗星曲线

errorbar –––– 绘制误差棒图
compass –––– 复数向量图(罗盘图)
feather –––– 复数向量投影图(羽毛图)
quiver –––– 向量场图
area –––– 区域图
pie –––– 饼图
convhull –––– 凸壳图
scatter –––– 离散点图

例,绘制阶梯曲线
x=0:pi/20:2*pi;y=sin(x);stairs(x,y)

例:阶梯绘图
h2=[1 1;1 -1];h4=[h2 h2;h2 -h2];
h8=[h4 h4;h4 -h4];t=1:8;
subplot(8,1,1);stairs(t,h8(1,:));axis('off')
subplot(8,1,2);stairs(t,h8(2,:));axis('off')
subplot(8,1,3);stairs(t,h8(3,:));axis('off')
subplot(8,1,4);stairs(t,h8(4,:));axis('off')
subplot(8,1,5);stairs(t,h8(5,:));axis('off')
subplot(8,1,6);stairs(t,h8(6,:));axis('off')
subplot(8,1,7);stairs(t,h8(7,:));axis('off')
subplot(8,1,8);stairs(t,h8(8,:));axis('off')

h2=[1 1;1 -1];h4=[h2 h2;h2 -h2];
h8=[h4 h4;h4 -h4];
t=1:8;
for i=1:8
subplot(8,1,i);
stairs(t,h8(i,:))
axis('off')
end

猜你喜欢

转载自blog.csdn.net/m0_37712157/article/details/83548319