爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4861|回复: 1

[作图] 使用gsn_add_annotation 出错

[复制链接]

新浪微博达人勋

发表于 2016-10-9 20:50:21 | 显示全部楼层 |阅读模式

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

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

x
我想画一个大的区域图 ,再从大区域中选出三个小区域,然后分别画在大图旁边。
但是脚本总算出错,各位帮忙看看吧
begin
  wks = gsn_open_wks("pdf","lake-location")
dir       = "/HOME/nwafu_climate_3/WORKSPACE/zqh/cesm121/run/TPlake/run/"
filename  = "TPlake.clm2.h0.2003.nc"
a         = addfile(dir+filename,"r")   
th        = a->TLAKE
tlake     = th*0.
copy_VarCoords(th,tlake)
   
shp_f       = "/HOME/nwafu_climate_3/WORKSPACE/zqh/cesm121/tp/tibetan.shp"
th_mask     = shapefile_mask_data(tlake(0,0,:,:),shp_f,True)
  gsn_define_colormap(wks,"BlRe")
  res                         = True
  res@gsnAddCyclic            = False
  res@gsnDraw                 = False
  res@gsnFrame                = False                  
  res@gsnMaximize             = True
  
  res@cnFillOn                = True
  res@cnLinesOn               = False
  res@cnLineLabelsOn          = False
              
  res@mpGeophysicalLineColor  = "Black"
  res@mpNationalLineColor     = "Black"
  res@mpLimbLineColor         = "Black"
  res@mpPerimLineColor        = "Black"
  res@mpUSStateLineColor      =  False
  res@mpLandFillColor         = "white"
  res@mpInlandWaterFillColor  = "white"
  res@mpOceanFillColor        = "white"
  res@mpGeophysicalLineThicknessF = 5
  res@gsLineThicknessF        = 5
  res@mpLimitMode             = "LatLon"
  res@pmTickMarkDisplayMode   = "Always"

  res@lbLabelAutoStride       = True
  res@lbBoxLinesOn            = False
  res@lbLabelBarOn            = False
  res@cnInfoLabelOn           = False
  res@cnLevelSelectionMode    ="ManualLevels"
  res@cnMinLevelValF          = 0
  res@cnMaxLevelValF          = 1
  res@cnLevelSpacingF         = 1
  res@gsnSpreadColorStart     = 12
  res@gsnSpreadColorEnd       = 13
  res@gsnLeftString           = ""
  res@gsnRightString          = ""
  res@gsnCenterString         = ""
  res@gsnCenterString         = ""  
  res@vpWidthF    = 0.4   ; Make plots small enough to fit in
  res@vpHeightF   = 0.4   ; unit square. Aspect ratio is preserved.

  plot    = gsn_csm_contour_map(wks,th(0,0,:,:),res)
;---Create map plot
  base_map = gsn_csm_map_ce(wks,res)
  shpfn1="/HOME/nwafu_climate_3/WORKSPACE/zqh/cesm121/tp/qh.shp"  
  qhres        = True
  qhres@mpGeophysicalLineThicknessF = 3
  qhres@gsLineThicknessF        = 3  
  qhres@mpMinLatF        = 36.5
  qhres@mpMinLonF        = 99.5
  qhres@mpMaxLatF        = 37.35
  qhres@mpMaxLonF        = 100.8
  map1 = gsn_csm_map(wks,qhres)
  shp_plot1     = gsn_add_shapefile_polygons(wks,map1,shpfn1,qhres)  
   
  shpfn2="/HOME/nwafu_climate_3/WORKSPACE/zqh/cesm121/tp/zhaling.shp"  
  zlres         = True  
  zlres@mpGeophysicalLineThicknessF = 3
  zlres@gsLineThicknessF        = 3
  zlres@mpMinLatF        = 34.75
  zlres@mpMinLonF        = 97
  zlres@mpMaxLatF        = 35.1
  zlres@mpMaxLonF        = 97.55
  map2 = gsn_csm_map(wks,zlres)
  shp_plot2     = gsn_add_shapefile_polylines(wks,map2,shpfn2,zlres)  
   
  shpfn3="/HOME/nwafu_climate_3/WORKSPACE/zqh/cesm121/tp/naco20131129.shp"  
  nmres        = True
  nmres@mpGeophysicalLineThicknessF = 3
  nmres@gsLineThicknessF        = 3
  nmres@mpMinLatF        = 30.45
  nmres@mpMinLonF        = 90.2
  nmres@mpMaxLatF        = 31
  nmres@mpMaxLonF        = 91.1  
  map3 = gsn_csm_map(wks,nmres)
  shp_plot3     = gsn_add_shapefile_polylines(wks,map3,shpfn3,nmres)  

;---Resources for adding 1,2plots to base_map.
  ares                   = True
  ares@amJust            = "TopRight"
  amid1 = gsn_add_annotation(base_map,shp_plot1,ares)
  bres                   = True
  bres@amJust            = "BottomRight"
  amid2 = gsn_add_annotation(base_map,shp_plot2,bres)
;---Attach third plot
  cres = True
  ares@amJust            = "TopLeft"
  amid3 = gsn_add_annotation(base_map,shp_plot3,cres)

;---This will draw everything, but it won't be maximized in frame.
   draw(base_map)
   frame(wks)
;
; maximize_output will resize graphics to maximize them
; on the page. This only works for PDF/PS output.
;
  pres             = True
  pres@gsnMaximize = True
  maximize_output(wks,pres)
end
  
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-10-9 21:08:32 | 显示全部楼层
错误是这个 fatal:NhlAddAnnotation: invalid view id
不好意思  忘了贴了  
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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