MATLAB教程(四):基础绘图

1. 绘图要素

  • 自变量 x = linspace(x1,x2);
  • 函数体 y = sin(x);
  • 标注:[ ]label()
    x轴: xlabel(‘str’);
    y轴:ylabel(‘str’);
    表头:title(‘str’);
  • :
    plot(x,y);
    plot(y); %x为1,2,3…
    plot(x1,y1,‘str’,…,xn,yn,‘str’);
    或者
    hold on
    plot(x1,y1,‘str’);
    plot(x2,y2,‘str’);
    hold off
    其中‘str’为plot styles,可以查看lineSpec
  • 图例
    legend(‘L1’,‘L2’);
  • text() and annotation():
    text(x,y,str,‘Interpreter’,‘latex’);
>> t = linspace(1,2);f = t.*t;g = sin(2*pi*t);
>> xlabel('Time(ms)');
>> ylabel('f(t)');
>> title('Mini Assignment#1');
>> plot(t,f,'k' ,t,g,'or');
>> legend('t^2','sin(2\pit)');
  • LaTex:
    用来表示数学表达式的一种文本
    如 str = '$ $\int_{0}^ {2} x ^ 2*sin(x) dx $$ ';

    整个式子表示 ∫ 0 2 x 2 ∗ s i n ( x ) d x \int_{0}^ {2} x ^ 2*sin(x) dx 02x2sin(x)dx
    $$表示文本开头/结束,\int_表示积分符号,{0}^{2}表示积分域
    - Annotation:
    annotation(‘arrow’,‘X’,[0.32,0.5],‘Y’,[0.6,0.4]);

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]);

2.Figure Adjustment

**对象属性(部分):**用到对象的继承

  • font
  • font size
  • line width
  • axis limit
  • tick position
  • tick label
    **修改对象属性:**用到指针 handle就是指针
    步骤:1、找到handle:曲线 h = plot(x,y); 数字gcf; 坐标 gca;
    2、修改属性:得到属性 get(property) 修改属性 set(handle,property,range) %不止一种格式
    set(gca,‘Xlim’,[0 , 2*pi]);

其他有用函数:allchild,ancestor,delete,findall

  • Multiple Figures:
    figure,plot(x,y1);
    figure,plot(x,y2);
    Figure Position and Size:
    figure(‘Position’,[left , botton ,width,height]);
    Plots in One Figure:
    subplot(m,n,k);
t=0:0.1:2*pi;x=3*cos(t);y=sin(t);
subplot(2,2,1);plot(x,y);axis normal
subplot(2,2,2);plot(x,y);axis square
subplot(2,2,3);plot(x,y);axis equal
subplot(2,2,4);plot(x,y);axis equal tight

Control of Grid,Box,and Axis
grid on/off box on/off axis on/off axis normal/square/equal/equaltight/image/ij/xy
Saving Figures into Files
saves(gcf,’’,’’);

你可能感兴趣的:(数学)