Matlab-plot_part1

1 图形标注及轴控制

(1)图形标注

title(‘图的题目')
xlabel(‘横轴的名称')
ylabel(‘纵轴的名称')
text(x,y,‘说明’)
legend(‘图例1’,‘图例2’,‘图例3')

(2)坐标、图形和图层窗口

axis equal  %纵横坐标轴采用等长刻度
axis square %产生正方形坐标系(默认为矩形)
axis auto   %使用默认设置
axis off    %取消坐标轴
axis on     %显示坐标轴
grid on     %显示网格
grid off    %不显示网格
box on      %显示其他轴(上、右)
box off     %不显示其他轴(上、右)
hold on     %继续在同一图层绘图

 2 在同一坐标系内画出多个图象

采用hold on,hold off

3 创建多个图象

新建一个画布:采用figure(n)

一张画布画多个图:subplot(m,n,p)或者 subplot(mnp) ;把当前窗口分成m×n个绘图区,m行,每行n个绘图区,区号按行优先编号。其中第p个区为当前活动区。每一个绘图区允许以不同的坐标系单独绘制图形

4 子图像

采用subplot(m,n,p):这个命令在当前图象窗口创建了 m×n 个子图象,按 m 行,n 列排列,并选择子图象 p来接受当前所有画图命令

例如: subplot(2,3,4)将会创建 6 个子图象,而且 subplot 4 是当前子图象

5  对画线的增强控制

采用 plot(x,y,'PropertyName',value,...);在自变量和函数之后被指定

6 文本字符串的高级控制

通过反斜杠转义实现特殊字符的输入”\”

\bf 黑体
\it 斜体
\rm 恢复正常字体
\fontname 字体的名字
\fontsize 字体的大小
_{xxx} xxx 做为某字符的上标
^{xxx} xxx 做为某字符的下标

举例:

 

7 极坐标图象

采用polar(theta,r),其是 theta 代表一个弧度角数组,r 代表一个距离数组,它用来画以角度为自变量的函数的极坐标图是非常有用的。

8 举例:

%创建第一幅图像
figure(1)

x=-2*pi:pi/20:2*pi;
y=sin(x);
plot(x,y,"b--");
title("figure(1) plot of sin(x) vs x");
axis on;
%当前轴的x,y的坐标范围,此处返回-8     8    -1     1
limits_now=axis;
disp(limits_now)
%重新设定轴的坐标范围
axis([-10 10 -1.5 1.5])

%hold on命令,在此坐标系内再增加一条曲线
hold on;
y2=cos(x);
plot(x,y2,"k-")
hold off%恢复 
legend('sin x','cos x');

%创建第二幅图像
figure(2)
y3=cos(-x-pi/4)
plot(x,y3,'o--')
legend('cos -x-pi/4');
title('figure(2)') ;
grid on

%创建第三幅图像,创建子图像
figure(3)
subplot(2,1,1);
%plot(x,y,'PropertyName',value,...) 
plot(x,y,'ro--','MarkerSize',9);
title('figure(3) Subplot 1 title');
subplot(2,1,2);
plot(x,y2);
title('figure(3) Subplot 2 title');

9 附加二维作图类型

如针头图(Stem Plots),阶梯图(stair plots),条形图,饼图(pie plots),罗盘图(compass plots)等;此外,它们还可以以三维形式出现,其函数分别为bar3,stem3,pie3和fill3。

%饼图
figure(4)
data = [10 37 5 6 6]; 
%explode 是一个逻辑数组,包含元素 1 和0。
%如果 explode 的值为1,那么它对应的扇区就从整体中分离出来
explode = [0 1 0 0 0]; 
pie(data, explode); 
title('\bfExample of a Pie Plot'); 
legend('One','Two','Three','Four','Five'); 

%针头图
figure(4)
x = [1 2 3 4 5 6]; 
y = [2 6 8 7 8 5]; 
stem(x,y); 
title('\bfExample of a Stem Plot'); 
xlabel('\bf\itx'); 
ylabel('\bf\ity'); 
axis([0 7 0 10]); 

%数值条形图
figure(5)
x = [1 2 3 4 5 6]; 
y = [2 6 8 7 8 5]; 
bar(x,y)
title('\bfExample of a bar Plot'); 
xlabel('\bf\itx'); 
ylabel('\bf\ity'); 
axis([0 7 0 10]); 

%极坐标图
figure(6)
x = [-5 1 2 3 4 5 6]; 
y = [-5 2 6 8 7 8 5]; 
compass(x,y)
title('\bfExample of a bar Plot'); 
xlabel('\bf\itx'); 
ylabel('\bf\ity');  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值