前言 MATLAB的繪圖功能十分強大,可以繪製各種各樣的圖形,數據可視化十分強大,但有時,採用默認的繪圖屬性,圖形的形式符合我們的要求,學會使用圖形句柄,並利用句柄修改屬性是十分重要的。
1.句柄之間的關係
在MATLAB中figure有句柄,axis有句柄,line,bar,plot等都有句柄,我們首先要搞清楚這些句柄的繼承關係,才能找到正確的句柄並修改其屬性的參數。
figure句柄<----axes句柄<----line句柄
<----plot句柄
<----bar句柄
........
annotation<----text
<----label
<----legend
........
2.常用的操作句柄的函數
2.1 獲取句柄
創建對象時,使用輸出參數。例如:hf=figure; hb=bar(X);
也可以使用h=gca獲取當前軸句柄,gcf獲取當前figure句柄,gco獲取當前活動句柄。
獲取父句柄子句柄,h1=get(h,'child');
2.2 獲取句柄所管理的屬性 get(h)
2.3 獲取句柄指定屬性的參數值 get(h,'propertyName');
2.4 修改句柄指定屬性的值 set(h,'propertyName',propertyValue)
3.常用句柄的屬性
1 Axes常用的屬性:
Box 'on'(default) , 'off'
GridLineStyle '-' ':' '-.' 'none'
LineStyleOrder LineSpec
LineWidth .5(default)
TickDir 'in'(default), 'out'
TickDirMode 'auto'(default), 'manual'
Visible 'on'(default), 'off'
XGrid,YGrid,ZGrid 'on', 'off'(default)
Children Handles of images, lights, lines,...
Parent Handler of the figure window
Position 設置軸在figure中的大小與位置,[leftbottom width height](歸一化的單位)
FontAngle 'normal'(de), 'italic', 'oblique'
FontName 字體類型
FontSize 10(de)
FontWeight 字體粗細 'normal', 'bold', 'light'
Title 標題 text句柄 注意:可以用text(x,y,'...')函數創建text對象
XLabel,YLabel,ZLabel 軸標籤 text句柄
XTick,YTick,ZTick 軸的劃分
XTickMode,.. 'auto','manual'
XTickLabel,... 軸刻度的標籤
XTickLabelMode 'auto', 'manual'
XAxisLocation x軸的位置 'bottom', 'top'
YAxisLocation y軸的位置 'left', 'right'
XLim,YLim,ZLim 軸的範圍
XLimMode,.. 'auto', 'manual'
XScale,.. 指定是線性刻度'linear',或對數刻度'log'
Color 背景顏色ColorSpec 'none'(de)
ColorOrder 指定線的顏色順序 m行3列的RGB矩陣
XColor,.. 軸的顏色ColorSpec
2 Line的常用的屬性
LineStyle - -- -. :
LineWidth .5(de)
Marker
MarkerEdgeColor 由ColorSpec指定
MarkerFaceColor ...
MarkerSize 6(de)
Color 線的顏色 ColorSpec指定
3 text對象的屬性
FontSize
FontAngle ‘normal’, ‘italic’
Color
Interpreter tex, latex