倾斜色标字体
res@lbLabelAngleF = 45 ; angle labels
只画指定值的等值线
res3@cnLevelSelectionMode = "ExplicitLevels"
res3@cnLevels = (/2/)
res3@cnMonoLineThickness = False
res3@cnLineThicknesses = (/2/)
ncl色标常用设置
res@lbOrientation="Vertical" ;竖直放置
res@lbBoxEndCapStyle = "TriangleBothEnds" ;两段为三角形
res@tmYRMode = "Automatic" ; turn off special labels on right axis
res@@lbLabelsOn = True
res@lbLabelFontHeightF = 0.02 ;set the size of label bar words
res@pmLabelBarHeightF = 0.15
res@tmYROn=False ;关闭刻度
;res@tmYRBorderOn =False ;关闭线
res@tmYRLabelsOn =False
resp@pmLabelBarParallelPosF = 0.17 ;色标左右移动
;resp@pmLabelBarOrthogonalPosF = -0.1 ;色标上下移动
resp@pmLabelBarWidthF = 0.5 ;长度
resp@pmLabelBarHeightF = 0.07 ;宽度
; resp@lbLabelFontHeightF = 0.015
坐标轴字体大小设置
res@tmXBLabelFontHeightF = 0.02 ;set the size of x-Axis words
res@tmYLLabelFontHeightF = 0.02 ;set the size of y-Axis words
注意极地投影经纬度的字体大小设置为:
res1@gsnPolarLabelFontHeightF= .04
res_vec@tmYRMode = "Automatic" ; turn off special labels on right axis
res_vec@tiYAxisString=""
res@tmYRLabelsOn = False
res@gsnPresHgtHeightLabelOn = False
colorbar设置
;res1@cnLevelSelectionMode= "ExplicitLevels"
;res1@cnLevels = (/-12,-10,-8,-6,-4,-2,0,2,4/); 值
;res1@cnFillColors = (/2,4,5,6,7,8,9,11,15,17,19/) ;颜色设置
res1@cnLevelSelectionMode = "ManualLevels" ; manually select levels
res1@cnLevelSpacingF = 0.5 ; contour spacing
res1@cnMinLevelValF = -4 ; min level
res1@cnMaxLevelValF = 4 ; max level
等值线标签
res1@cnInfoLabelOn = False
等值线数值标签
res1@cnLineLabelsOn =False
;等值线数值标签
res3@cnLineLabelsOn = True
res3@cnLineLabelAngleF=0 ;标签角度
res3@cnLineLabelBackgroundColor ="white";标签边框内部颜色
res3@cnLineLabelDensityF=0.5 ;修改等值线上标签数目的相对密度
res3@cnLineLabelPerimOn=True ;添加边框
res3@cnLineLabelPerimColor="white" ;边框颜色
res3@cnLineLabelPlacementMode="Computed" ;绘制标签的算法
res3@cnLineLabelFontHeightF =0.025
图片之间间隔
resp@gsnPanelYWhiteSpacePercent=3
数组维度转换
z_D1 =f_z->$varnameh$(D,{levP},{lat1:lat2},:)
z_D = reshape(z_D1,(/1,dsizes(0),dsizes(1)/))
printVarSummary(z_D)
创建文件若存在则删除
outFx="/raid63/xran/Research_ERA5/why/TN_Fulx_data/TN2001-Fx"+fmon+""+fyear+".monthly.nc"
if (isfilepresent(outFx)) then
system("rm -f "+outFx)
end if
提取每一年对应的月
ctime = time(fstep:lstep:12) ;每年对应的月
nctime = dimsizes(ctime)
zvar = zvarorg(fstep:lstep:12,:,:,:)
组图一张图时不居中
resp@gsnPanelCenter = False
时间提取
yyyymm = cd_calendar(eof_ts&time,-2)/100
xy轴型图片添加网格
;res1@tmXMajorGrid= True;, Turns on the grid in the x-direction.
;res1@tmXMajorGridThicknessF = 1.0 ; 2.0 is default
;res1@tmXMajorGridLineDashPattern = 2 ; select short dash lines
;res1@tmYMajorGrid = True ; implement y grid
;res1@tmYMajorGridThicknessF = 1.0 ; 2.0 is default
;res1@tmYMajorGridLineDashPattern = 2 ; select short dash lines
计算月平均值
calculate_monthly_values
具体使用见ncl官网
读取一年的每日值(时间,水平,纬度,经度)并计算月平均值。该值为类型为“short”,带有scale_factor和“加法偏移量”。n基准是指“时间”维度(n基准=0)。
f = addfile("air.day.2008.nc","r")
x = short2flt(f->air)
printVarSummary(x)
opt = True
opt@nval_crit = 12 ; require at least 12 values for the "avg" is calculated.
xMon = calculate_monthly_values (x, "avg", 0,opt)
printVarSummary(xMon)
输出如下所示:
Variable: xMon
Type: float
Number of Dimensions: 4
Dimensions and sizes: [time | 12] x [level | 17] x [lat | 73] x [lon | 144]
Coordinates:
time: [17593032..17601072]
level: [1000..10]
lat: [90..-90]
lon: [ 0..357.5]
维度
nlat = dimsizes(lat)
nlon = dimsizes(lon)
nlevel = dimsizes(level)
res_vec@tmYRMode = "Automatic" ; turn off special labels on right axis
将变量输出保存
运行ncl命令时ncl *.ncl >&1.txt将变量输出保存
出图图片旋转
gsnPaperOrientation = ″portrait″(纵向)″landscape″(横向)
°符号
["+youwantlats+"-"+youwantlate+"~S~o~N~N]
提取变量的时间维度
date = cd_calendar(x&time,-2) ; yyyymmdd
yrfrac = yyyymmdd_to_yyyyfrac (date, 0)
delete(yrfrac@long_name)
delete(x@long_name)
pStrt = 19950101 ; 4 years: winter 96-97 MJO gold standard
pLast = 19981231
iStrt = ind(date.eq.pStrt) ; user specified dates
iLast = ind(date.eq.pLast)
delete(date)
间隔
res1@mpGridLonSpacingF = 90.
;地图上经度与纬度线的间隔
res1@gsnMajorLonSpacing=90
res1@gsnMajorLatSpacing=20
;地图上网格的间隔
res1@mpGridAndLimbOn = True
res1@mpGridLatSpacingF = 20
res1@mpGridLonSpacingF = 90
res1@mpGridLineDashPattern = 1
res1@mpGridLineColor ="black"
res1@mpGridLineThicknessF =0.5
底图地图线的颜色和粗细
res1@mpGeophysicalLineColor = "gray"
res1@mpGeophysicalLineThicknessF = 0.5; - Changes the thickness of continental outlines.
XY轴刻度线标签
;XY轴的标签不显示
res_vec@tmYLLabelsOn=False
res_vec@tmXBLabelsOn=False
;某一幅图显示,其他不显示数值,但图片大小不一致,控制子图的属性;
res@gsnMaximize= False
resPanel@gsnMaximize = True
;调节图片间距
;展板中各子图空白间距过大如何调节?增加空白间隙距离的
resPanel@gsnPanelYWhiteSpacePercent = 0.5
resPanel@gsnPanelXWhiteSpacePercent = 0.2
;调整各子图的位置减小间隙
resPanel@gsnPanelXF = (/0.1,0.38,0.66,0.1,0.38,0.66/) ;各个子图的横向位置
resPanel@gsnPanelYF = (/-1,-1,-1,-1,-1,-1/) ;-1是默认值
子图标号
resPanel@gsnPanelFigureStrings = (/"(a)","(b)","(c)","(d)","(e)","(f)"/)
resPanel@gsnPanelFigureStringsFontHeightF = 0.02
resPanel@amJust = "TopLeft" ;位置,默认是在右下方
resPanel@gsnPanelFigureStringsPerimOn = False ;去掉方框的边框
resPanel@gsnPanelFigureStringsBackgroundFillColor =-1 ;方框背景设置为透明
极地投影坐标距离图片
res@gsnPolarLabelDistance=1.08 ;默认为1.04
reverse colormap
cmap = read_colormap_file("precip4_diff_19lev") ; read color data
cmap = cmap(::-1,:) ; reverse colormap
res@cnFillPalette = cmap
colorbar选择颜色区域
res@gsnSpreadColors=True
res@gsnSpreadColorStart=100
res@gsnSpreadColorEnd=255