matlab畫圖設置(坐標軸、曲線、顏色)


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')



本文轉載自海中南《matlab畫圖設置(坐標軸、曲線、顏色)》


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM