NCL笔记:Fill填色

https://www.ncl.ucar.edu/Applications/color.shtml
res@cnFillOn                 = True    ; 首先打开填色(如果不设置cnFillColors或cnFillPalette使用默认填色)
;注意,以下①②③之间是独立的不同方法
;①①①①①①①①①①①①①①①---------------------------------------------
res@cnFillPalette             = "precip_11lev" ;选择现成的调色板,名称在这里
;https://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml#Rainbow
;②②②②②②②②②②②②②②②----------------------------------------------
colors = (/"white","royal blue","light sky blue",\
    "powder blue","light sea green",\
            "pale green","wheat","brown","pink"/) ;自定义color array(不要和背景前景相同),名称见
;https://www.ncl.ucar.edu/Document/Graphics/named_colors.shtml
res@cnFillPalette       = colors
;③③③③③③③③③③③③③③③----------------------------------------------
res@cnFillColors        = (/-1,4,9,19,35,81,75,91,99/) ;从color map中自行选择颜色组成colorbar,-1为透明,colormap数字代码见
;https://www.ncl.ucar.edu/Applications/colormap.shtml
;或 https://www.ncl.ucar.edu/Document/Graphics/ColorTables/ncl_default.shtml
;④④④④④④④④④④④④④④④----------------------------------------------
gsn_define_colormap(wks,"circular_0") ;该函数为wks定义一个colormap,colormap可用现成的调色板(如例①)或者自定义(如例②)
res@cnFillColors              = (/10,11,12,13,14,15,16,17,18,19/) ;从上句话定义的colormap中选取颜色(区别与例③中的colormap是默认的)
;==============================================
画多个panel统一给出colorbar
wks = gsn_open_wks("png", "test_wuhan_rain2")
plot = new(2,graphic)
res                           = True
res@cnFillOn             = True
res@gsnDraw            = False             ; Do not draw plot
res@gsnFrame          = False            ; Do not advance frame
res@lbLabelBarOn      = False             ; turn off the label bar
res@lbOrientation   = "Vertical" ;设置colorbal方向
plot(0) = gsn_csm_contour_map_ce(wks, p(0,:,:), res)
plot(1) = gsn_csm_contour_map_ce(wks, p(3,:,:), res)
resPanel              = True              ; panel mods desired
resPanel@gsnPanelLabelBar= True               ; label bar on panel
gsn_panel(wks,plot,(/2,1/),resPanel)
;==============================================
; 画colormap并翻转colormap,用于debug
wks = gsn_open_wks("x11","color")
gsn_define_colormap(wks,"gui_default")      ;选一个colormap,如果没有这个步骤下一步会画默认colormap
gsn_draw_colormap(wks)                    ; 画colormap;V6.3支持新函数draw_color_palette(wks,"MPL_Paired",False)
gsn_reverse_colormap(wks)                 ; 将当前wks的colormap进行翻转
gsn_draw_colormap(wks)                    ; 画colormap
;==============================================
;同一个wks中用2个以上的colormap:对不同的graphic重新设置cnFillPalette/cnFillColors即可;如果是流线图和矢量图则设置stLevelPalette或者vcLevelPalette
wks = gsn_open_wks("png", "test_wuhan_rain2")
plot = new(2,graphic)
res                         = True
res@gsnDraw            = False       ; do not draw picture
res@gsnFrame           = False       ; do not advance frame
res@cnFillOn                 = True    ; turn on color fill
res@cnFillPalette            = "precip_11lev"
plot(0) = gsn_csm_contour_map_ce(wks, p(0,:,:), res)
res@cnFillPalette  = "wgne15"
plot(1) = gsn_csm_contour_map_ce(wks, p(3,:,:), res)
resPanel              = True              ; panel mods desired
gsn_panel(wks,plot,(/2,1/),resPanel)
;==============================================
;读取自定义的RGB文件作为colormap
wks = gsn_open_wks("x11","color") 
cmap = RGBtoCmap("test_rgb.txt")               ; RCGtoCmap将文本文件的RGB转化为NCL colormap
gsn_define_colormap(wks,cmap) 
gsn_draw_colormap(wks)
《test_rgb.txt》
220 220 220
95 158 160
221 160 221
205 200 177
238 233 191
78 238 148
238  99 99
139  10   80
139 126 102
139  69 19
;==============================================
;采用自定义rgb数组作为colormap
wks = gsn_open_wks("png","color")           ; open a workstation and send data to PNG
 
colors = (/ (/255,255,255/), (/244,255,244/), \
            (/217,255,217/), (/163,255,163/), (/106,255,106/), \
            (/43,255,106/), (/0,224,0/), (/0,134,0/),(/255,255,0/),\
            (/255,127,0/) /) / 255.   ; 确保是浮点型
res                   = True 
res@cnFillOn           = True 
res@cnFillPalette       = colors
plot = gsn_csm_contour_map(wks,prc(0,:,:), res)
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值