Matlab绘图基本控制命令
(2011-05-07 14:34:45)
标签:
杂谈 |
分类: 实用软件技巧 |
图形的控制与表现 (Figure
control and representation)
MATLAB提供的用于图形控制的函数和命令:
subplot: 将图形窗口分成N块子窗口。
1.图形窗口(figure
window)
(1). 图形窗口的创建和选择(Creating and selecting of figure
window)
(2). 在一个图形窗口中绘制多个子图形(Drawing
several subfigures in a single
window)
subplot(m,n,p):把窗口分成m×n个小窗口,并把第p个窗口当作当前窗口。
例:将4 个图形显示在同一个图形窗口中。
(3).
在一个已有的图形上绘图(Drawing a figure on the figure was
existed)
例:将peaks函数的等高线图与伪彩色画在一起。
2.坐标轴控制命令(Axis control
commands)
axis(xmin xmax ymin ymax)
axis
auto
axis manual(或axis(axis)):保持刻度不随数据的大小而变化
axis tight
axis
ij
axis
xy
axis equal
axis
square
axis
normal
axis off
axis on
(1) 坐标轴的范围(Domain of
coordinates
axis)
二维图形坐标轴范围在缺省状态下是根据数据的大小自动设置的,如欲改变,可利用axis(xmin
xmax ymin ymax),函数来定义。
例: 定义坐标轴范围对观察图形的影响。
x=0:.01:pi/2; figure(1); plot(x,tan(x),'-ro')
%使图形难于进行观察和判断。
figure(2); plot(x,tan(x),'-ro'); axis([0,
pi/2,0,5])
(2)
显示比例对绘图结果的影响(Effect of display scaling on plotting
results)
例:比较(Default, axis square, axis equal, axis
tight)几种不同的显示方式的显示效果。
t=0:pi/20:2*pi; figure(1);
subplot(2,1,1); plot(sin(t),2*cos(t)); grid on
subplot(2,1,2); plot(sin(t),2*cos(t)); axis square; grid on
figure(2)
subplot(1,2,1); plot(sin(t),2*cos(t)) ; axis equal; grid on
subplot(1,2,2); plot(sin(t),2*cos(t)); axis tight ; grid on
3.图形标注(Marking on the figure):MATLAB的图形标注方法(表
6—7)
xlabel :x轴标注,
ylabel :y轴标注,
legent :标注图例
图形标注可以使用字母,数字,汉字或按规定的方法表示希腊字母。如:\pi表示π,\leq表示≤,\rm表示后面的字恢复为正体字,\it表示斜体字,FontSize表示字体的大小,
FontName表示字体的类型等。
可以使用图形窗口的Insert菜单,也可以使用属性编辑器,还可以使用函数输入的方法加标注,以下介绍相关函数的使用方法。
(1). 加注坐标轴标识和图形标题(Add
axis labels and title of figure)
加注坐标轴标识:xlabel(‘s’),
ylabel(‘s’)
例:加注坐标轴标示和图形标题。
(2). 图中加注文本(Add text
in the
figure)
text(x,y,’字符串’)
例:在上图中加语句。
句中:
leftarrow
rightarrow
HorizontalAlignment 表示右对齐水平排列
gtext('字符串'): 在图形窗口上用鼠标直接在指定的位置上加注文本。
例:
(3).
指定TeX字符
例:在标题中指定TeX字符
在title中的字符串表现的是 Aeαt
斜体Ae 上标斜体αt
(4). 在图形中添加图例框(Add
legend in the
figure)
legend(字符串1,字符串2,…)
例:在当前图形中添加图例说明。
legend函数的其他功能见(表 6—8)
4.
图线形式和颜色(Style and color of plot)
(1). 图线的形式: (style of
plot)
标记点类型:点'.', 圆'o', 加号'+',
星号'*',
命令:plot(x,y,'—'),
plot(x1,y1,':’,x2,y2,'*')
例1:选择不同的线形绘图。
例2:选择不同的标记点绘图。
(2). 线的颜色(color of
plot)
可选颜色: 红r,绿g, 蓝b, 黄y, 粉红m, 青c,
黑k.
例:t=0:pi/20:2*pi;
(3). 图线的其他属性(other
characters of plot)
设置图线的宽度
标记点的边缘颜色: 'MarkerEdgeColor'
填充颜色
标记点的大小
例: 设置图线的线形、颜色、宽度、标记点的颜色及大小。