请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6221|回复: 3

[作图] panel中gsn_add_polyline的问题

[复制链接]

新浪微博达人勋

发表于 2020-11-12 11:36:44 | 显示全部楼层 |阅读模式

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

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

x
本人使用循环语句读取资料,用panel  一页画多图,加上gsn_add_polyline画框后,单独出图均有框,但是多图中仅最后一张图有框,请大神们指点,哪里出了问题?


系统提示:warning:TransformPostDraw: tfPolyDrawList element 0 is invalid,没太搞懂是什么意思



load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"

begin
nx=144
ny=72
n=15 ;except mme and obs
lat = fspan(-88.75,88.75,72)
lon = fspan(1.25,358.75,144)
lat@units = "degrees_north"
lon@units = "degrees_east"


eqm=new((/n/),string)
eqm=(/"ACCESS1-0","bcc-csm1-1","CNRM-CM5","FGOALS-s2","GFDL-ESM2G","GISS-E2-H","inmcm4","IPSL-CM5A-LR","IPSL-CM5A-MR","MIROC5","MIROC-ESM","MPI-ESM-LR","MPI-ESM-MR","MRI-CGCM3","NorESM1-M"/)
fig=new((/n/),string)
fig=(/"(a)","(b)","(c)","(d)","(e)","(f)","(g)","(h)","(i)","(j)","(k)","(l)","(m)","(n)","(o)"/)

wks=gsn_open_wks("png","panel-c4xp")
gsn_define_colormap(wks,"BlueRedGray")
plot=new(15,graphic)
;dum=new(15,graphic)

a=addfile("cmip_obs_cha.nc","r")
arry = new((/72,144/),double)

  ;diri = "/mnt/d/ncl/qihou/pr/"
diri = "/mnt/d/ncl/qihou/pr/cli/"
  obs=addfile(diri+"OBSp.nc","r")
  op=obs->pr(:,::-1,:)
  op_a=dim_avg_n(op,0)
  op_a!0="lat"
  op_a!1="lon"
  op_a&lat=lat
  op_a&lon=lon
arryb = new((/72,144/),double)


         gres               = True
         gres@gsLineColor   = "Black";"Gray"
         gres@gsLineThicknessF= 2.0
         gres@tfPolyDrawOrder = "postDraw"  ; this can be used for polylines, polymarkers, or polygons

lon1 = (/107.25,114.24,114.24,107.25,107.25/)
lat1 = (/24.63,24.63,30.29,30.29,24.63/)

  do k =0,n-1
     print(eqm(k))

arry=a->pr(k,:,:)
arry!0="lat"
arry!1="lon"
arry&lat=lat
arry&lon=lon

arryb=arry/op_a*100.
arryb!0="lat"
arryb!1="lon"
arryb&lat=lat
arryb&lon=lon

res                     = True            
; res@gsnDraw             = False              ; don't draw yet      不要翻页!!!!
  res@gsnFrame            = False              ; don't advance frame yet
  res@cnInfoLabelOn = False
  res@cnFillOn            =True                                           ; turn on color   
  res@gsnSpreadColors     = True               ; use full color map
  res@cnLinesOn           = False                                    ; no contour lines
  res@lbLabelBarOn =False    ;关闭每张图的色标
  res@cnLevelSelectionMode="ExplicitLevels"
  res@cnLevels=(/-80,-50,-25,0,25,50,80/)
  res@cnFillColors=(/2,34,66,127,128,187,220,253/)
  res@tmXBLabelFontHeightF     = 0.014         ; adjust some font heights
  res@tmYLLabelFontHeightF     = 0.014
  res@tiMainFontHeightF        = 0.022
  res@txFontHeightF            = 0.017


res@mpMinLatF                  = 22.5
res@mpMaxLatF                  = 32.5
res@mpMinLonF                  = 105.
res@mpMaxLonF                  = 115.
res@mpFillOn                  = False
res@mpOutlineOn                = True
;设置map
res@mpDataSetName = "Earth..4"
res@mpDataBaseVersion = "MediumRes"
res@mpOutlineDrawOrder = "PostDraw"
res@mpGridSpacingF = 10
res@mpProvincialLineColor = "Black"
res@mpNationalLineColor = "Black"
res@mpNationalLineThicknessF = 2.0
res@mpOutlineBoundarySets = "AllBoundaries"
res@gsnLeftString=fig(k)+eqm(k)
res@gsnRightString="%"
res@cnInfoLabelOn = False

plot(k)= gsn_csm_contour_map(wks,arryb(:,:),res)   



dum=gsn_add_polyline(wks,plot(k),lon1,lat1,gres)
draw(plot(k))
frame(wks)

delete(arry)
delete(dum)
end do

resP=True
resP@gsnPanelLabelBar=True
;resP@gsnPanelSave = True
resP@gsnFrame        = False
gsn_panel(wks,plot,(/4,4/),resP)

end


panel-c4xp.000012.png
panel-c4xp.000017.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-11-13 13:36:16 | 显示全部楼层
是因为在画panel图之前前面delete(dum)啦
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-11-16 11:22:59 | 显示全部楼层
刚好碰到类似的问题,参考了ncl-talk上的一个帖子(talk_archives/2012/1771),我的问题就解决了。
贴不了链接,把回复贴一下吧

Hi Erik,

Since this example uses only gsn_add_polyxxxx, and not gsn_polyxxx_ndc,
or gsn_polyxxxx, you should be able to panel the plots just fine.

The key is that anytime you call gsn_add_polyxxxx, you need to make sure the
variable on the left side of the "=" is always unique. If you don't do this, then
only the last polylines that you add will be visible.

So, using the example you pointed to, and assuming you already have
an array of plots that you want to panel, you would do something like this
to add the lines:

; create array of dummy graphic variables. This is required, b/c each line
; must be associated with a unique dummy variable.

  dum = new((/nplots,4/),graphic)

; draw each line separately. Each line must contain two points.
  do n=0,nplots-1
    do i = 0 , 3
      dum(n,i)=gsn_add_polyline(wks,plot(n),xpts(i:i+1),ypts(i:i+1),resp)
    end do
  end do
. . .

  dum_gons = new((/nplots,3/),graphic)
  do n=0,nplots-1
    dum_gons(n,0) = gsn_add_polygon(wks,plot(n),xtri,ytri,resp)
     . . .
    dum_gons(n,1) = gsn_add_polygon(wks,plot(n),xtri+10,ytri,resp)
    . . .
    dum_gons(n,2) = gsn_add_polygon(wks,plot(n),xtri+20,ytri,resp)

  end do

  gsn_panel(wks,plot,...)

密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-11-17 12:25:41 | 显示全部楼层
shine00 发表于 2020-11-16 11:22
刚好碰到类似的问题,参考了ncl-talk上的一个帖子(talk_archives/2012/1771),我的问题就解决了。
贴不 ...

太感谢了  问题已经解决
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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