爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9936|回复: 1

[作图] ncl绘制counter

[复制链接]
发表于 2021-3-15 17:43:18 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
大家好,我使用ncl绘制nc文件并叠加了shapefile地图。 因为只想显示部分区域,所以在范围设置 res@mpMinLatF 等直接设置了想要区域的经纬度。结果输出的时候地图的经纬度与nc文件的范围不匹配,下方是展示的图和ncl脚本。谢谢大家


begin
f1 = addfile ("GRIDCRO2D.1km.20150102", "r")
f  = addfile("aver_day_lay1.nc","r")

do nh=0,1
p  = f->PMFINE(nh,0,:,:)
p@lat2d = f1->LAT(0,0,:,:)
p@lon2d = f1->LON(0,0,:,:)            
;=================================================;
; PLOT 2
;=================================================;
wks = gsn_open_wks("png",nh)      ; send graphics to PNG file
res                   = True              ; plot mods desired
;res@lbOrientation="vertical"

res@cnLevelSpacingF     = 0.08
res@cnMinLevelValF=.0002
res@cnMaxLevelValF=.8

;res@lgLabelStride=3
;res@tiMainString="PM2.5 Concentration"
res@tmYLLabelFontHeightF     = 0.028
dims = dimsizes(p@lat2d)
  res@mpLimitMode            = "Corners"          ; choose region of map
  res@mpLeftCornerLatF       =22.084; min(p@lat2d)
  res@mpLeftCornerLonF       =113.7705; min(p@lon2d)
  res@mpRightCornerLatF      =22.6217; max(p@lat2d)
  res@mpRightCornerLonF      =114.4273; max(p@lon2d)
;res@mpPolarLabelSpacing="0.5"

  res@mpProjection           = "LambertConformal"
  res@mpLambertParallel1F    = 15.
  res@mpLambertParallel2F    = 40.
  res@mpLambertMeridianF     = 114.

  res@pmTickMarkDisplayMode = "Always"
  res@mpFillOn              = False           ; turn off map fill
  res@mpOutlineOn           = False           ; only plot shp file

;  res@mpOutlineDrawOrder    = "PostDraw"      ; draw continental outline last
;  res@mpOutlineBoundarySets = "GeophysicalAndUSStates" ; state boundaries
;--------------------------------------------
; usually, when data is placed onto a map, it is TRANSFORMED to the specified
; projection. Since this model is already on a native lambert conformal grid,
; we want to turn OFF the transformation.
;--------------------------------------------
  res@tfDoNDCOverlay = True
; res@tfDoNDCOverlay = "NDCViewport"          ; NCL V6.5.0 or later
;--------------------------------------------
  res@gsnMaximize         = True          ; maximize plot size
  res@gsnLeftString=" "
  res@gsnRightString=" "
  res@cnLevelSelectionMode="ManualLevels"

  res@cnFillOn              = True            ; color plot desired
  res@cnLinesOn             = False           ; turn off contour lines
  res@cnFillPalette         = "WhBlGrYeRe"    ; NCV_rainbow2 set color map MPL_Reds MPL_pink WhBlGrYeRe MPL_gist_heat
  res@gsnAddCyclic          = False           ; regional data
;res@gsnreverse_colormap      = "BlAqGrYeOrRe"
;res@cnLevelSelectionMode  = "ExplicitLevels"
;res@cnLevels              = (/15,35,55,75,95,115,150/)
;res@cnFillColors          =(/130,135,159,164,177,180,193,224/)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

res@lbBoxMinorExtentF=0.15

res@tmYLMinorPerMajor = 0                 ;次刻度尺
res@tmXBMinorPerMajor = 0
res@tmYRLabelsOn = False
res@tmYRMinorPerMajor = 0
res@tmXTMinorPerMajor = 0
res@tmYROn = False
res@tmXTOn = False
res@tmXMajorGrid=False                    ;网格线
res@tmXBMajorOutwardLengthF = False
res@tmYLMajorOutwardLengthF = False

  plot = gsn_csm_contour_map(wks,p(:,:),res)       ; contour the variable
  shpfn2="hk.shp"

shpres=  True
shpres@gsLineThicknessF   =  5                    ;-- increase line thickness地图线深浅
shpres@gsLineColor        = "black"  

dumstr1           = unique_string("poly")           ;-- generate string 'dumstr1'
  plot@$dumstr1$    = gsn_add_shapefile_polylines(wks,plot,shpfn2,shpres)  ;-- add polylines

draw(plot)       ;-- draw the plot
frame(wks)       ;-- advance the frame

end do   

; In this file, the coordinate variables of the data are listed as
; lat and long, but they are really just index points, which makes this
; data suitable for plotting without a map.

  end


error.png
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2021-3-15 21:03:07 | 显示全部楼层
我会了!在第一步确定变量的时候  p  = f->PMFINE(nh,0,:,:)  就可以确定网格的范围,然后根据网格的范围修改经纬度,输出的图就是和地图相匹配的了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表