1. 基础绘图
1.1 根据Data画图
1.1.1 plot()
plot(x, y)
plot(y) % 其中x = [1...n], n = length(y)
- 比如:
plot(cos(o:pi/20:2*pi));

1.1.2 hold on/off
hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off

1.2 绘图形式
-
plot(x, y, 'str')
:'str'
见下表:
数据标识 |
线型 |
颜色 |
. |
- |
k |
* |
- - |
b |
X |
-. |
c |
请见官方文档
1.2.1 legend()
x=0:0.5:4*pi;
y=sin(x);
h=cos(x);
w=1./(1+exp(-x));
g=(1/(2*pi*2)^0.5).*exp((-1.*(x-2*pi).^2)./(2*2^2));
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,g,'c^-');
% 添加右上角的图例注释
legend('sin(x)','cos(x)','Sigmoid','Gauss function');

1.2.2 title()
和label()
title()
xlabel()
ylabel()
zlabel()
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = exp(-x);
plot(x, y1, '--*', x, y2, ':o');
xlabel('t = 0 to 2\pi');
ylabel('values of sin(t) and e^{-x}')
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');
1.2.3 text()
和annotation()
x = linspace(0,3);
y = x.^2.*sin(x);
plot(x,y);
line([2,2],[0,2^2*sin(2)]);
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex');
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);
1.2.4 EX
t = 1:0.1:2;
f = t^2;
g = sin(2*pi*t);
plot(t, f, '-b', t, g, 'or');
2. 图形对象参数