1. 程式人生 > >matlab中legend的高頻用法

matlab中legend的高頻用法

legend函式的基本用法是:

legend('string1','string2','string3', ...)

分別將字串1、字串2、字串3……標註到圖中,每個字串按先後次序對應作圖時的圖示。

例如:

plot(x,sin(x),'.b',x,cos(x),'+r')
legend('sin','cos')

這樣可以把".“標識為’sin’,把”+“標識為"cos”

legend的位置引數

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

L=legend('sin','cos')
set(L,'location','northwest')

可以將標識框放置在圖的左上角。

legend大小的調整

調整legend的大小主要用到fontsize的屬性 例如: legend('sin','cos','fontsize',12)

或者

   L=legend('sin','cos')
    set(T,'fontsize',12)

legend對tex數學公式的顯示