本文目录

title([‘The ‘ num2str(iter) ‘th generation’], ‘FontName’,’Times New Roman’,’FontSize’,10);
xlabel(‘$x_{1}$’,’Interpreter’,’LaTex’,’FontName’,’Times New Roman’,’FontSize’,10);

ylabel(‘$x_{2}$’,’Interpreter’,’LaTex’,’FontName’,’Times New Roman’,’FontSize’,10);

gtext(‘Omega^{0}’,’FontName’,’Times New Roman’,’FontSize’,10);

set(gca,’XTick’,[0:pi/3:2*pi]) 设置所要显示坐标轴刻度,

set(gca,’XTickLabel’,[0:pi/3:2*pi]) 给这些数据加标签

set(gca,’FontName’,’Times New Roman’,’FontSize’,10) 设置坐标轴字体

gca是单词Get current axes handle的缩写,获得坐标轴句柄。(不知道matlab为什么不自动对应数据加标签,还需要多一条命令)出来的图形

坐标轴标注:

1. 控制坐标轴尺度长度:set(gca,’XLim’,[-pi/2 pi])

2. 定制自己想标注的刻度:

(1)set(gca,’XTick’,[-pi/2:pi/4:pi]) %%%坐标轴最小值,步长,最大值

(2)set(gca,’XTickLabel’,{‘-pi/2’ ‘-pi/4:’ ‘0’ ‘pi/4’ ‘pi/2’ ‘pi*3/4’ ‘pi’})

3. 反转坐标轴:set(gca,’XDir’,’reverse’)

4. 上下标及latex公式

输下标:_{wb}

输上标:^{0.5}

输latex公式:

text(‘Interpreter’,’latex’,…

‘String’,’$$int_0^x!int_y dF(u,v)$$’,…

‘Position’,[.5 .5],…

‘FontSize’,16)
在Matlab中输入上标、下标、特殊符号或字体:
bf,it,rm表示黑体,斜体,正体字符

上标用 ^(指数),下标用 _(下划线)

调用方式为: ^{任意字符}, _{任意字符}, 注意{}的使用!

希腊字母等特殊字符用 加拼音如:
后字母大写的,表示是大写(如Ω Omega),小字母的,表示小写(如ω omega)

α alpha β beta γ gamma θ theta Θ Theta

Г Gamma δ delta Δ Delta ξ xi Ξ Xi Ω Omega

η elta ε epsilong ζ zeta μ miu υ nu τ tau

λ lamda Λ Lamda π pi Π Pi σ sigma Σ Sigma

φ phi Φ Phi ψ psi Ψ Psi χ chi ω omega

< leq > geq 不等于 neq << ll >> gg

正负 pm 左箭头 leftarrow 右箭头 rightarrow 上箭头 uparrow

体会以下两例:

figure, title(‘zeta^{-t}sint’);

figure, title(‘x~{chi}_{alpha}^{2}(3)’);

5. 坐标轴的视点

1、坐标轴的视点(viewpoint):从哪个方向看整个坐标系统,这决定了坐标轴的方向和位置,通过view函数实现视点的设置;

view([z y ]):(将坐标系统想象为一座房子,而自己是个会飞的天使,最初你在房子的北,海拔角度为0的位置,这是时你的视角是view[0 0],之后可以根据需要设置z和y的值,分别是绕房子转动的方向,和沿空间轴向上妃的高度)z表示视角沿z轴(正方向)旋转的角度,y表示视角沿y轴(水平面)旋转的角度

2、坐标轴显示、关闭、样式

axis off; % 去掉坐标轴
axis tight; % 紧坐标轴
axis equal; % 等比坐标轴
axis([-0.1, 8.1, -1.1, 1.1]); % 坐标轴的显示范围

% gca: gca, h=figure(…);
set(gca, ‘XLim’,[3 40]); % X轴的数据显示范围
set(gca, ‘XTick’,[-3.14,0,3.14] ); % X轴的记号点
set(gca, ‘XTicklabel’,{‘-pi’,’0′,’pi’}); % X轴的记号
set(gca, ‘XTick’, []); % 清除X轴的记号点
set(gca, ‘XGrid’,’on’); % X轴的网格
set(gca, ‘XDir’,’reverse’); % 逆转X轴
set(gca, ‘XColor’,’red’); % X轴的颜色
3、设置x,y轴位置

set(gca,’YAxisLocation’,’right’) % y轴的刻度设置到右侧

更多介绍:

a=linspace(1,2,10)

plot(a,’–pr’,’linewidth’,1.5,’MarkerEdgeColor’,’r’,’MarkerFaceColor’,’m’,’MarkerSize’,10)

legend(‘a’,’Location’,’best’)

title(‘a’,’FontName’,’Times New Roman’,’FontWeight’,’Bold’,’FontSize’,16)

xlabel(‘T’,’FontName’,’Times New Roman’,’FontSize’,14)

ylabel(‘a’,’FontName’,’Times New Roman’,’FontSize’,14,’Rotation’,0)

axis auto equal

set(gca,’FontName’,’Times New Roman’,’FontSize’,14)

1.曲线线型、颜色和标记点类型

plot(X1,Y1,LineSpec, …) 通过字符串LineSpec指定曲线的线型、颜色及数据点的标记类型。

    线型            颜色        数据点标记类型

标识符  意义     标识符意义     标识符   意义

   –    实线     r   红色        +     加号

   -. 点划线     g   绿色            圆圈

  —    虚线     b   蓝色        *     星号

   :    点线     c  蓝绿色             点

                 m  洋红色         交叉符号

                 y   黄色   square(或s) 方格

                 k   黑色  diamond(或d) 菱形

                   白色        向上的三角形

                                v  向下的三角形

                                >  向左的三角形

                                <  向右的三角形

                            pentagram(或p) 五边形

                             hexagram(或h) 六边形

2.设置曲线线宽、标记点大小,标记点边框颜色和标记点填充颜色等。

plot(…,’Property Name’, Property Value, …)

Property Name 意义    选项

LineWidth 线宽    数值,如0.5,1等,单位为points

MarkerEdgeColor 标记点边框线条颜色颜色字符,如’g’, ’b’等

MarkerFaceColor 标记点内部区域填充颜色颜色字符

MarkerSize 标记点大小   数值,单位为points

3.坐标轴设置

范围设置:

a. axis([xmin xmax ymin ymax])设置坐标轴在指定的区间

b. axis auto 将当前绘图区的坐标轴范围设置为MATLAB自动调整的区间

c. axis manual 冻结当前坐标轴范围,以后叠加绘图都在当前坐标轴范围内显示

d. axis tight 采用紧密模式设置当前坐标轴范围,即以用户数据范围为坐标轴范围比例:

a. axis equal 等比例坐标轴

b. axis square 以当前坐标轴范围为基础,将坐标轴区域调整为方格形

c. axis normal 自动调整纵横轴比例,使当前坐标轴范围内的图形显示达到最佳效果

范围选项和比例设置可以联合使用,默认的设置为axis auto normal

4.坐标轴刻度设置

set(gca, ’XTick’, [0 1 2]) X坐标轴刻度数据点位置

set(gca,’XTickLabel’,{‘a’,’b’,’c’}) X坐标轴刻度处显示的字符

set(gca,’FontName’,’Times New Roman’,’FontSize’,14)设置坐标轴刻度字体名称,大小

‘FontWeight’,’bold’ 加粗 ‘FontAngle’,’italic’ 斜体

对字体的设置也可以用在title, xlabel, ylabel等中

5.图例

legend(‘a’,’Location’,’best’) 图例位置放在最佳位置

6.更多的设置可以在绘图窗口中打开绘图工具,Inspector… 中查找

Various line types, plot symbols and colors may be obtained with

PLOT(X,Y,S) where S is a character string made from one element

from any or all the following 3 columns:

         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

         w     white       v     triangle (down)

                          ^     triangle (up)

                          <     triangle (left)

                          >     triangle (right)

                          p     pentagram

                          h     hexagram

在使用Matlab时,经常需要将得到的数值表达成二维或三维图像。

plot(vector1,vector2)可以用来画两个矢量的二维图,例如

x=1:0.1:2*pi;

plot(x,sin(x))可以画正弦函数在0-2pi的上的图像。

plot函数可以接一些参数,来改变所画图像的属性(颜色,图像元素等)。下面是一些属性的说明

          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

例如,plot(x,y,’.r’)表示用点来画图,点的颜色是红色。

plot函数可以接一些参数,来改变所画图像的属性(颜色,图像元素等)。下面是一些属性的说明

          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

   Example

      x = -pi:pi/10:pi;

      y = tan(sin(x)) – sin(tan(x));

      plot(x,y,’–rs’,’LineWidth’,2,…

                      ‘MarkerEdgeColor’,’k’,…

                      ‘MarkerFaceColor’,’g’,…

                      ‘MarkerSize’,10)

          xlabel(‘x’);

          ylabel(‘y’);

·         用Matlab画图时,有时候需要对各种图标进行标注,例如,用“+”代表A的运动情况,“*”代表B的运动情况。

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) 来指定图例标识框的位置

这些是Matlab help文件。后面一段是对应的翻译和说明

       ‘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

       ‘North’             图例标识放在图顶端

       ‘South’            图例标识放在图底端

       ‘East’               图例标识放在图右方

       ‘West’              图例标识放在图左方

       ‘NorthEast’       图例标识放在图右上方(默认)

       ‘NorthWest      图例标识放在图左上方

       ‘SouthEast’      图例标识放在图右下角

       ‘SouthWest’     图例标识放在图左下角

(以上几个都是将图例标识放在框图内)

       ‘NorthOutside’          图例标识放在图框外侧上方

       ‘SouthOutside’         图例标识放在图框外侧下方

       ‘EastOutside’           图例标识放在图框外侧右方

       ‘WestOutside’          图例标识放在图框外侧左方

       ‘NorthEastOutside’   图例标识放在图框外侧右上方

       ‘NorthWestOutside’ 图例标识放在图框外侧左上方

       ‘SouthEastOutside’   图例标识放在图框外侧右下方

       ‘SouthWestOutside’ 图例标识放在图框外侧左下方

(以上几个将图例标识放在框图外)

       ‘Best’                      图标标识放在图框内不与图冲突的最佳位置

       ‘BestOutside’           图标标识放在图框外使用最小空间的最佳位置

还是用上面的例子

legend(‘sin’,’cos’,’location’,’northwest’)可以将标识框放置在图的左上角。

   Examples:

       x = 0:.2:12;

       plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x));

       legend(‘First’,’Second’,’Third’);

       legend(‘First’,’Second’,’Third’,’Location’,’NorthEastOutside’)

       b = bar(rand(10,5),’stacked’); colormap(summer); hold on

       x = plot(1:10,5*rand(10,1),’marker’,’square’,’markersize’,12,…

                ‘markeredgecolor’,’y’,’markerfacecolor’,[.6 0 .6],…

                ‘linestyle’,’-‘,’color’,’r’,’linewidth’,2); hold off

       legend([b,x],’Carrots’,’Peas’,’Peppers’,’Green Beans’,…

                 ‘Cucumbers’,’Eggplant’)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注