MATLAB进阶绘图
1、plot()的使用
1.1作用
在特定的范围内产生数值;
在一个图表中显示数据点;
1.2用法
plot(x,y) 和 plot(y)
例如:plot(cos(0:pi/20:2*pi);
在一个表格中有两个plot(),显示中可以使用
hold on/off,否则只会显示一个曲线。
2、legend()和标记函数
使用用于在表格中注释,解释每条曲线代表的含义如legend(‘L1’…);
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');
标记函数title()
xlabel()
ylabel()
zlabel()
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]);
str=’
∫
0
2
x
2
sin
(
x
)
d
x
\int_{0}^ {2} x^2\sin(x) dx
∫02x2sin(x)dx’;
此句在坐标轴中显示∫ x²sin(x)dx,积分区间0-2
\int 表示∫
{0}^ {2} 表示积分区间
x^2\sin(x) 表示被积函数
dx 表示微分
Figure Adjustment
一些属性Font
FontSize
LineWidth
AxisLimit
Tickposition
TickLbel
Modifying Properties of An Object
Utility function
gca return the handle of the “current” axes
gcf return the handle of the “current” figureto fetch properties use get()
to modify properties use set()
例如:
x=linspace(0,2*pi,1000);y=sin(x);plot(x,y);
h=plot(x,y);get(h)
改变坐标轴取值范围
set(gca,'XLim',[0,2*pi]);
set(gca,'YLim',[-1.2,1.2]);
改变坐标间隔
set(gca,'FontSize',25);
x轴显示0 90 180 270 360
set(gca,'XTick',0:pi/2:2*pi);
set(gca,'XTickLabel',0:90:360);
x轴显示0 2/pi pi 3pi/2 2pi
set(gca,'FontName','symbol');
set(gca,'XTickLabel',{'0','p/2','p','3p/2','2p'});
Marker Specificator
figure position and size
figure(‘Position’,[left,bottom,width,height]);
对于要显示多个plot(),可以用subplot(m,n,1)
m指行
n指列
1指在矩阵中显示的位置