NCL学习教程
https://ncl.readthedocs.io/zh_CN/latest/
NCL色带在太湖上的路径
/GFPS8p/xyyang/wk/lib/NCL-6.6.2/lib/ncarg/colormaps
设置工作空间
setvalues NhlGetWorkspaceObjectId()
“wsMaximumSize” : 9000000000
end setvalues
查看变量的相关信息
printVarSummary(temp) ;查看变量的信息
printMinMax(T, 1) ;查看变量的最大最小值
快速绘图
res@cnFillMode = “RasterFill” ;采用rasterfill的方法填色
标题
res@tiMainString = “TROPOMI NO~B~2~N~ VCD 2019 January” ;设置主要标题
图片左上方和右上方的标题
res@gsnLeftString = “(c) NH~B1~3~N~ in March, 2019”
res@gsnLeftString = “PM”+”(“+”~F33~m”+”~F25~g/m~S1~3”+”)”
res@gsnLeftStringFontHeightF = 18 ;设置左上标题的字体大小
res@gsnRightString = “TROPOMI NO~B~2~N~ VCD 2019 January” ;设置右上标题
res@gsnRightStringFontHeightF = 18 ;设置右上标题的字体大小
res@gsnRightString = “PM~B~2.5~N~”
;调参考速度
uvres@vcRefAnnoOrthogonalPosF = -0.15 ;上下 负值为向上.负绝对值越大越上
;调整label Bar:
res@pmLabelBarWidthF = 0.11 ;改变labelbar的厚度及距图的远近.
res@pmLabelBarHeightF = 0.73 ;调整labelbar长短
res@lbLabelFontHeightF = 0.014 ;调整labelbar 字体大小
给图片的XY轴加上经纬度的说明
res@tiXAxisString = “Longitude”
res@tiYAxisString = “Latitude”
res@pmTickMarkDisplayMode = “Always” ; Turn on map tickmarks
色带
res@gsnSpreadColors = True ; use full color map
如果想只使用colorbar里面的部分颜色,可进行如下设置(gsnSpreadColors = True才可以)
res@gsnSpreadColorStart = 10 ;代表开始的颜色
res@gsnSpreadColorEnd = 199 ;代表结束的颜色 如果为负值则为倒数第N个
res@lbOrientation = “Vertical” ;设置colorbar的位置 如不设置则默认水平
res@lbBoxSeparatorLinesOn = False ;去除colorbar里面的box line 变为MATLAB连续色带的效果
res@lbBoxEndCapStyle ;调整色带为GradS类似的箭头
res@lbTitleString = “NO~B~2~N~ column density (10~S~15~N~ molec/cm~S~2~N~)” ; 设置色带的标题
res@lbTitleFontHeightF = 0.018
res@lbTitlePosition = “Bottom” ;设置色带的位置,放在图片的下方
res@lbTitleDirection = “Across” ; letter angle
res@lbTitleAngleF = 90. ; title angle
res@lbLabelStride = 5 ;设置隔几个间隔开始绘制色带标签
res@lbBoxMinorExtentF = 0.15 ;– decrease the height of the labelbar
uvres@vcRefAnnoOrthogonalPosF = -0.15 ;调参考速度,上下负值为向上。负绝对值越大越上
;调整label Bar:
res@pmLabelBarWidthF = 0.11 ;改变labelbar的厚度及距图的远近
res@pmLabelBarHeightF = 0.73 ;调整labelbar长短
res@lbLabelFontHeightF = 0.014 ;调整labelbar 字体大小
res@pmLabelBarOrthogonalPosF = 0.1 ;move label bar closer
控制绘图网格
res@mpLimitMode = “Corners” ; choose region of map
模型数据用下面4行
res@mpLeftCornerLatF = XLAT_I(0,50)
res@mpLeftCornerLonF = XLONG_I(0,0)
res@mpRightCornerLatF = XLAT_I(nlat-1,nlon-1)
res@mpRightCornerLonF = XLONG_I(nlat-1,nlon-50)
卫星数据用下面4行
res@mpLeftCornerLatF = 12
res@mpLeftCornerLonF = 81
res@mpRightCornerLatF = 52
res@mpRightCornerLonF = 140
设置网格线 gridline
res@mpGridAndLimbOn = True ;– plot grid lines
res@mpGridSpacingF = 1 ;– grid line spacing 1 degree
res@mpGridLineThicknessF = 2.0 ;– make grid lines thicker
res@mpGridLineColor = “Gray30” ;– grid line color
设置投影类型和绘图的中心经纬度
res@pmTickMarkDisplayMode = “Always” ;使用NCL默认的lon和lat标签
res@mpProjection = “LambertConformal”
res@mpLambertParallel1F = 25
res@mpLambertParallel2F = 40
res@mpLambertMeridianF = 110
图片美化
res@tmXTOn=False ;关闭上边界的凸起
res@tmXTLabelsOn = False ;关闭图片上侧的标签
res@tmYROn=False ;关闭右边界的凸起
res@tmYRLabelsOn = False ;关闭图片右侧的标签
res@tmXBLabelAngleF = 45 ;x轴标注旋转45度变为斜体
res@tmXBLabelDeltaF = -0.8 ;将x轴标注往图片方向平移-缩小标签间距
res@tmYLLabelDeltaF = -0.8 ;将y轴标注往图片方向平移-缩小标签间距
设置等值线
res@cnFillOn = True ;根据等值线进行填色
res@cnFillPalette = “rainbow” ;change the colormap
res@cnLinesOn = False ;只填色 不画等值线
方法I
res@cnLevelSelectionMode = “ExplicitLevels”
res@cnLevels = fspan(0,250,9)
方法II
res@cnLevelSelectionMode = “ManualLevels”
res@cnMinLevelValF = 0 ;– minimum contour level
res@cnMaxLevelValF = 20 ;– maximum contour level
res@cnLevelSpacingF =0.2 ;– contour level spacing
最终绘图操作
plot = gsn_csm_contour_map(wks, var, res)
注意点
- Shapefile文件从5.1.1版开始支持,注意“shpfile”文件至少要包括”.shp”、”.shx”及”.dbf”
- 自定义经纬标签 These tickmarks are actually part of the TickMark object, and are not created by gsn_code.ncl,and hence they don’t recognize any of the gsnMajor/Minor resources. These tickmarks are not very customizable unfortunately. If you want more custom tickmarks, see example mptick_9.ncl at: http://www.ncl.ucar.edu/Applications/mptick.shtml#ex9 You will need to copy the “add_map_tickmarks” function to the top of your script, and then call it after you create your map, with something like: res@tmYLValues = ispan(51,53,1) ; this gives you tickmarks and labels at 51, 52, and 53 res@tmXBValues = ispan(11,15,1) ; 11, 12, 13, 14, 15 ;—Attach the new map tickmarks. map = add_map_tickmarks(wks,map,res) You can look at examples mptick_10 and mptick_11 for other methods.