NCL自定义绘制色标图例

【需求分析】当你在绘制组图时,很多东西要自己控制,其中色标可能是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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容