- 积分
 - 20258
 
	- 贡献
 -  
 
	- 精华
 
	- 在线时间
 -  小时
 
	- 注册时间
 - 2014-7-8
 
	- 最后登录
 - 1970-1-1
 
 
 
 
 
 
 | 
	
 
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册 
 
 
 
x
 
 本帖最后由 风子 于 2016-3-29 13:00 编辑  
 
© 版权所有 2014-2016, MCS强.  本帖允许转载,但须注明出处并附有原文链接 
 
初版: 16 July, 2014 
重格式化版: 29 March, 2016 
 
******************************************************************************************* 
          方法一和方法二为官网给出的两种特定等值线加粗方法 
          方法三为我个人根据官网信息编写的特定等值线加粗子程序 
******************************************************************************************* 
经常有人询问NCL中怎么加粗特定的等值线,但是却得不到像GrADS中一样的直接设置,因为没有专门的源属性,那么我们该如何加粗特定的等值线呢? 
为此NCL官网给出了两种方法,如下: 
 
#1 Overlay程序 (通常用来叠加不同的图形变量)
 
 - res@gsnDraw = False  ; 先不画图层和框架
 
 - res@gsnFrame = False
 
 - ;; 绘制想要加粗的等值线图层并叠加到原图层
 
 - res2 = True  ; 定义源变量2
 
 - res2@gsnFrame = False                                        
 
 - res2@gsnDraw = False
 
 - res2@cnLevelSelectionMode ="ExplicitLevels"  ; 设置等值线线阶选择模式
 
 - res2@cnLevels = the_contour_level_of_interest  ; 设置想加粗的等值线值
 
 - res2@cnLineThicknessF = thickness  ; 设置加粗的等值线粗细值
 
 - res2@cnLineColor = color  ; 设置加粗的等值线颜色
 
 - second_plot = gsn_csm_contour(wks, data, res2)   ; 绘制加粗等值线的图层
 
 - overlay(plot,second_plot)  ; 叠加图层到原图层
 
 - draw(plot)
 
 - frame(wks)
 
  复制代码 
#2 设定cnLevels和cnLineThicknesses数组 注意以下两个源的区别 
cnLineThicknessF     //当单一线粗设定为真时,该源规定所有等值线同样的粗细      
   When cnMonoLineThickness is True, this resource sets a uniformline  
   thickness for all contour lines.      
   Default: 1.0  
cnLineThicknesses    //当单一线粗设定为否时,该源规定每一条等值线的粗细设定      
   If cnMonoLineThickness  is False, each element of this arrayresource specifies the line  
   thickness of a contour line drawn at thecorresponding contour level. If the array is not set  
   explicitly, allelements default to the value 1.0.  If the array currently containsfewer elements  
   than cnLevelCount , more elements will be addedto the array and set to the default value,  
   1.0; existing elements withvalid line thicknesses (greater than 0.0) will not be modified.      
   Default: 1.0 for all elements  
相应的我们可以设置如下
 - res@cnLevelSelectionMode = "ExplicitLevels"
 
 - res@cnLevels = (/-5, -3, -2, -1, 0, 1, 2, 3, 5/)
 
 - res@cnMonoLineThickness = False
 
 - res@cnLineThicknesses = (/1, 1, 3, 1, 1, 1, 1, 1, 1/)
 
  复制代码 
#3 调用子程序实现一条语句搞定等值线加粗  附件为指定等值线加粗的子程序,请将其内容黏贴到你的 myfoo.ncl 文件,没有的话请创建myfoo.ncl 文件为个人的函数程序库,通常建议在该文件中编写自己的程序或函数,以后每次编写NCL脚本请同时载入自己的函数库myfoo.ncl 
thick_specified_contourF调用介绍 
 
thick_specified_contourF( plot[1]:graphic , thickLevel:float , \\ 
                          thickValue:float , cnMapOverlay:integer) 
参数一:plot   你想加粗等值线所在图形变量(如plot) 
参数二:thickLevel   你想加粗的等值线值 
参数三:thickValue   你想加粗的等值线的粗细值 
参数四:cnMapOverlay  如果您使用gsn_csm_contour_map_overlay,想给第二个等值线系统的 
                      某条等值线加粗,请设置该参数值为2.  默认请设置为 -1 
 
重要的事: 该子程序加在plot后,因此必须设置 
                      res@gsnDraw = False 
                      res@gsnFrame = False 
 
示例用法: thick_specified_contourF( plot , 5860 , 4.0 , -1 ) 
说明:加粗5860线,设置粗细为4.0 
注意:若所选等值线不在cnLevles中,本程序将强制添加所选等值线值, 
      同时等值线信息(cnInfo***)将被关掉 例: - begin
 
 - ;---读取数据文件 
 
 -     fil  = addfile("/home/svane/Scripts/NCL_Scripts/hgt.2013.nc","r")
 
 -     hgt = short2flt(fil->hgt(0,5,:,:))
 
 - ;---打开绘图工作台
 
 -     wks = gsn_open_wks("ps","hgt_500")
 
 - ;---建立源变量并设定属性 
 
 -     res = True
 
 -     res@gsnDraw = False
 
 -     res@gsnFrame = False
 
 -     res@cnLevelSelectionMode = "ManualLevels"
 
 -     res@cnMinLevelValF = 5000
 
 -     res@cnMaxLevelValF = 5900
 
 -     res@cnLevelSpacingF = 40
 
 -     res@cnLineLabelInterval = 1
 
 -     res@mpMinLatF =   0.
 
 -     res@mpMaxLatF =  60.
 
 -     res@mpMinLonF =  80.
 
 -     res@mpMaxLonF = 140.
 
 - ;---绘图并加粗特定等值线
 
 -     plot = gsn_csm_contour_map_ce(wks,hgt,res)
 
 -     thick_specified_contourF(plot,5860,4,-1)
 
 - ;---绘制图形变量并将工作台写入文件
 
 -     draw(plot)
 
 -     frame(wks)
 
 - end
 
  复制代码 
 效果:(上例效果为图一) 
 
 
 
 
 昨天兰溪指出使用gsn_csm_contour_map_overlay来加粗指定等值线,对一些情况比较适用  
  鉴于该方式与方法一并无实质区别,并有一定局限性,这里并不将此列为一种新方法 
  具体用法: 
  与方法一类似,但将以下两句 
- second_plot = gsn_csm_contour(wks,data,res2)
 
 - overlay(plot,second_plot)
 
  复制代码   合并为 - gsn_csm_contour_map_overlay(wks,data,data,res1,res2)
 
  复制代码 
 
© 版权所有 2016, MCS强. 16 July 2014, 转载请注明出处并附有原文链接 
 
 |   
 
评分
- 
查看全部评分
 
 
 
 
 
 |