加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

NCL填色图(以contour为例)

(2018-04-11 16:16:18)
分类: NCL
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)


0

阅读 收藏 喜欢 打印举报/Report
后一篇:NCLcontourlevel
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有