matlab——二维绘图函数及部分参数

来源:百度文库 编辑:神马文学网 时间:2024/04/30 04:41:59
2009-10-21 10:02
MATLAB基本xy平面绘图命令
plot: x轴和y轴均为线性刻度(Linear scale)
loglog: x轴和y轴均为对数刻度(Logarithmic scale)
semilogx: x轴为对数刻度,y轴为线性刻度
semilogy: x轴为线性刻度,y轴为对数刻度
注:
若要画出多条曲线,只需将座标对依次放入plot函数即可:
plot(x, sin(x), x, cos(x));
若要改变颜色,在座标对後面加上相关字串即可:
plot(x, sin(x), 'c', x, cos(x), 'g');
若要同时改变颜色及图线型态(Line style),也是在座标对後面加上相关字串即可:
plot(x, sin(x), 'co', x, cos(x), 'g*');
axis([xmin,xmax,ymin,ymax])函数可以调整图轴的范围:
axis([0, 6, -1.2, 1.2]);
补充:下面是一些参数的说明
b     blue(蓝色)       .     point(点)       -     solid(实线)
g     green(绿色)      o     circle(圆圈)    :     dotted(点线)
r     red(红色)        x     x-mark(叉号)    -.    dashdot (点画线)
c     cyan(墨绿色)     +     plus(加号)       --    dashed(虚线)
m     magenta(紫红色) *     star(星号)      (none) no line
y     yellow(黄色)     s     square(正方形)
k     black(黑色)      d     diamond(菱形)
v     triangle (down)(下三角形)
^     triangle (up)(上三角形)
<     triangle (left)(左三角形)
>     triangle (right)(右三角形)
p     pentagram(五角星)
h     hexagram(六芒星)
此外,MATLAB也可对图形加上各种注解与处理:
xlabel('Input Value'); % x轴注解
ylabel('Function Value'); % y轴注解
title('Two Trigonometric Functions'); % 图形标题
legend('y = sin(x)','y = cos(x)'); % 图形注解
grid on; % 显示格线(反之为grid off)
hold on; % 保持图形(反之为hold off)
我们可用subplot来同时画出数个小图形於同一个视窗之中:
subplot(2,2,1); plot(x, sin(x));
subplot(2,2,2); plot(x, cos(x));
subplot(2,2,3); plot(x, sinh(x));
subplot(2,2,4); plot(x, cosh(x));
====================================================
其他各种二维绘图函数
bar 长条图(适合资料点数量不多的情况)
errorbar 图形加上误差范围(如果已知资料的误差量,就可用errorbar来表示): errorbar(x,y,e); % e是误差量
fplot 较精确的函数图形(对于变化剧烈的函数,可用fplot来进行较精确的绘图,会对剧烈变化处进行较密集的取样):fplot('sin(1/x)', [0.02 0.2]); % [0.02 0.2]是绘图范围
polar 极坐标图
hist 累计图(对于大量的资料,可用hist来显示资料的分布情况和统计特性)
rose 极座标累计图
stairs 阶梯图(将资料点视为多边行顶点,并将此多边行涂上颜色)
stem 针状图(常被用来绘制数位讯号)
fill 实心图
feather 羽毛图(将每一个资料点视复数,并以箭号画出)
compass 罗盘图(和feather很接近,只是每个箭号的起点都在圆点)
quiver 向量场图
====================================================
legend函数的基本用法
LEGEND(string1,string2,string3, ...)
分别将字符串1、字符串2、字符串3……标注到图中,每个字符串对应的图标为画图时的图标。
例如:
plot(x,sin(x),'.b',x,cos(x),'+r')
legend('sin','cos')这样可以把"."标识为'sin',把"+"标识为"cos"
还可以用LEGEND(...,'Location',LOC) 来指定图例标识框的位置,下面是LOC内容的说明
将图例标识放在框图内:
'North'              inside plot box near top(图例标识放在图顶端)
'South'              inside bottom(图例标识放在图底端)
'East'               inside right(图例标识放在图右方)
'West'               inside left(图例标识放在图左方)
'NorthEast'          inside top right (default)(图例标识放在图右上方(默认))
'NorthWest           inside top left(图例标识放在图左上角)
'SouthEast'          inside bottom right(图例标识放在图右下角)
'SouthWest'          inside bottom left(图例标识放在图左下角)
将图例标识放在框图外:
'NorthOutside'       outside plot box near top(图例标识放在图框外侧上方)
'SouthOutside'       outside bottom(图例标识放在图框外侧下方)
'EastOutside'        outside right(图例标识放在图框外侧右方)
'WestOutside'        outside left(图例标识放在图框外侧左方)
'NorthEastOutside'   outside top right(图例标识放在图框外侧右上方)
'NorthWestOutside'   outside top left(图例标识放在图框外侧左上方)
'SouthEastOutside'   outside bottom right(图例标识放在图框外侧右下方)
'SouthWestOutside'   outside bottom left(图例标识放在图框外侧左下方)
其他:
'Best'               least conflict with data in plot(图标标识放在图框内不与图冲突的最佳位置)
'BestOutside'        least unused space outside plot(图标标识放在图框外使用最小空间的最佳位置)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/bobwang_bupt/archive/2010/08/12/5803205.aspx