科学计算科学计算 (23).pdf
AnnotationsAxes appearanceRetain plot when adding new plotsDivide the figure4 4.2 2 FormattingFormatting andand AnnotationAnnotation1 1AnnotationsAnnotationstitlexlabelylabeltextlegend(1)The title Function Basic Syntaxtitle(txt)x=-2*pi:0.05:2*pi;y=sin(x);plot(x,y)title(y=sin(x)title(MATLAB,y=sin(x)1 1AnnotationsAnnotationsExample 1 Plot sine over-2,2,and add a title to the plot.title(y=cosomegat)title(y=eaxt)title(X_1geqX_2)title(bfy=cosomegat+beta)Font ModifierDescriptionbfBold fontitItalic fontrmNormal font1 1AnnotationsAnnotations(1)The title Function TeX MarkupMATLAB supports a subset of TeX markup.Use TeX markup to add superscripts and subscripts,modify the font type and color,and include special characters in the text.Color Text color title(y=cosomegat,Color,r)title(y=cosomegat,FontSize,24)FontSize Title font size1 1AnnotationsAnnotations(1)The title Function Using name-value pair argumentstitle(txt,Name,Value)x=-2*pi:0.05:2*pi;y=sin(x);plot(x,y)title(y=sin(x)xlabel(-2pi leq x leq 2pi)1 1AnnotationsAnnotations(2)The xlabel and ylabel Functionxlabel(txt)ylabel(txt)Plot the sine curve over-2,2,and label the x-axis.text(-2*pi,0,-2pi)text(3,0.28,leftarrow sin(x)1 1AnnotationsAnnotations(3)The text Functiontext(x,y,txt)Add a text description to the previous plot.x=linspace(0,2*pi,100);plot(x,sin(x);sin(2*x);sin(3*x)legend(sin(x),sin(2x),sin(3x)1 1AnnotationsAnnotations(4)The legend Functionlegend(label1,label2,.)Example 2 Plot sine curves with different frequencies and create a legend with descriptive labels for each plotted data series.2 2Axes AppearanceAxes Appearanceaxisgridbox axis(-pi,pi,-4,4)(1)axisBasic syntaxaxis(xmin,xmax,ymin,ymax,zmin,zmax )2 2Axes AppearanceAxes Appearance2 2Axes AppearanceAxes Appearance(2)axisOther axis style and modeaxis equal:Use the same length for the data units along each axis.axis square:Use axis lines with equal lengths.Adjust the increments between data units accordingly.axis auto:Automatically choose all axis limits.axis off:Hide axes lines and background axis on:Display axes lines and background x=0,1,1,0,0;y=0,0,1,1,0;plot(x,y)axis(-0.1,1.1,-0.1,1.1)axis equal;2 2Axes AppearanceAxes Appearancegrid ongrid offgrid2 2Axes AppearanceAxes Appearance(2)Display or hide axes grid linesbox onbox offboxDisplay or hide axes outlinex=linspace(0,2*pi,100);y=sin(x);sin(2*x);sin(0.5*x);plot(x,y)axis(0 7-1.2,1.2)title(不同频率正弦函数曲线不同频率正弦函数曲线);xlabel(Variable X);ylabel(Variable Y);text(2.5,sin(2.5),sin(x);text(1.5,sin(2*1.5),sin(2x);text(5.5,sin(0.5*5.5),sin(0.5x);legend(sin(x),sin(2x),sin(0.5x)grid onExample 3 Plot sinx、sin(2x)、sin(x/2),and add annotations to the plot.3 3Retain plot when adding new plotsRetain plot when adding new plotshold onhold offholdt=linspace(0,2*pi,100);x=sin(t);y=cos(t);plot(x,y,b)hold on;plot(2*x,2*y,r-)grid onaxis(-2.2 2.2-2.2 2.2)axis equalExample 4 Use hold on commamd to plot two concentric circles.subplot:the plot created in an axes.Syntaxsubplot(m,n,p)Arguments m and n specify the figure divided into an m-by-n grid.Argument p specifiesthat the p-th subplot is active plot zone.4 4Divide the figureDivide the figure subplot(2,2,1);x=linspace(0,2*pi,60);y=sin(x);plot(x,y);title(sin(x);axis(0,2*pi,-1,1);x=linspace(0,2*pi,60);subplot(2,2,1)plot(x,sin(x)-1);title(sin(x)-1);axis(0,2*pi,-2,0)subplot(2,1,2)plot(x,cos(x)+1);title(cos(x)+1);axis(0,2*pi,0,2)subplot(4,4,3)plot(x,tan(x);title(tan(x);axis(0,2*pi,-40,40)subplot(4,4,8)plot(x,cot(x);title(cot(x);axis(0,2*pi,-35,35)4 4Divide the figureDivide the figure