【需求分析】当你在绘制组图时,很多东西要自己控制,其中色标可能是1个或者2个甚至更多,这样就需要自己定义色标针对的图形、色标的尺寸、色标的尺寸等。因为多次之后,发现这个程序直接放在ncl脚本的前面,然后直接调用非常方便。
【调用示例】lbdiy = labelbar(wks,plot(0,0,2))
【程序代码】代码如下:
;********************************************************************
; This function creates and draws a labelbar based on a given
; contour plot.
;********************************************************************
function labelbar(wks,plot)
local colors, levels, labels, nboxes
begin
; Retrieve the contour levels and their associated colors.
getvalues plot
"cnLevels" : levels
"cnFillColors" : colors
end getvalues
nboxes = dimsizes(colors)
labels = ""+levels ; labels for the labelbar
; Set some labelbar resources.
lbres = True
lbres@vpXF = 0.05 ; Position labelbar at
lbres@vpYF = 0.95-0.3-0.05 ; bottom center of frame.
lbres@vpWidthF = 0.80
lbres@vpHeightF = 0.10
lbres@lbPerimOn = False ; Turn off perimeter.
lbres@lbOrientation = "Horizontal" ; Default is vertical.
lbres@lbFillColors = colors
lbres@lbMonoFillPattern = True ; Fill them all solid.
lbres@lbLabelFontHeightF = 0.015 ; Label font height
lbres@lbLabelAlignment = "InteriorEdges"
lbid = gsn_create_labelbar(wks,nboxes,labels,lbres)
draw(lbid) ; Draw labelbar
return(lbid) ; Return it so we can maximize later if desired.
end