爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 13164|回复: 5

求助帖:关于overlay的问题

[复制链接]
发表于 2021-3-9 11:26:26 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 Jacqueline007 于 2021-3-9 15:31 编辑

【已解决】中午好,有一个问题想请教一下大家。我一共画了五张图,其中包括两张填色的底图:base1、 base2     以及三张线条图:line1、 line2 、line3
我的目的是分别在base1和base2两张底图上overlay   line1 、line2 、line3这三张线条图,得到最终结果:
base1+line1+line2+line3 、base2+line1+line2+line3
程序运行后出错,显示overlay的tranform图是已经叠加过的,但是我的tranform图就是普通的gsn_csm_contour画出来的,并没有叠加map之类的函数,所以不知道该如何解决,烦请大家指教。


fatal:NhlAddOverlay: tranform is already an annotation or overlay: 131          fatal:NhlAddOverlay: tranform is already an annotation or overlay: 164          fatal:NhlAddOverlay: tranform is already an annotation or overlay: 197

begin
    f=addfile("new_hgt.nc","r");hgt(initial_time0_hours, g0_lat_1, g0_lon_2)
        f1=addfile("hgt.grib","r");;Z_GDS0_ISBL_S123 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
    timeARR    = cd_calendar(f->initial_time0_hours,-5)
    yrARR            = timeARR(:,0)
    monARR            = timeARR(:,1)
        ;底图填色-------------------------------------------------------------------------------------
        ;climate
        hgt=f->hgt(:,{-20:40},{0:180})
        hgta=dim_avg_n_Wrap(hgt,0)
        ;NW Pattern
        timeInd1=ind(yrARR.eq.1987.or.yrARR.eq.1988.or.yrARR.eq.1996.or.yrARR.eq.2010.or.yrARR.eq.2019.or.yrARR.eq.2020)
        hgt1=f->hgt(timeInd1,{-20:40},{0:180})
        hgt1a=dim_avg_n_Wrap(hgt1,0)
        hgt_dif1=hgt1a-hgta  ;117.469  -48.5216
        copy_VarMeta(hgt1a,hgt_dif1)
        ;SE Pattern
        timeInd2=ind(yrARR.eq.1990.or.yrARR.eq.1997.or.yrARR.eq.1999.or.yrARR.eq.2001.or.yrARR.eq.2006.or. \
     yrARR.eq.2012.or.yrARR.eq.2014.or.yrARR.eq.2018)
        hgt2=f->hgt(timeInd2,{-20:40},{0:180})
        hgt2a=dim_avg_n_Wrap(hgt2,0)
        hgt_dif2=hgt2a-hgta    ;67.7029  -86.2909
        copy_VarMeta(hgt2a,hgt_dif2)        
        ;划线5880西太副高轮廓-------------------------------------------------------------------------
    ;climate
        Line=f1->Z_GDS0_ISBL_S123(:,{-20:40},{0:180})
        Linea=dim_avg_n_Wrap(Line,0) ;编号1
        ;NW Pattern
        Line1=f1->Z_GDS0_ISBL_S123(timeInd1,{-20:40},{0:180})
        Line1a=dim_avg_n_Wrap(Line1,0)  ;编号2
        ;SE Pattern
        Line2=f1->Z_GDS0_ISBL_S123(timeInd2,{-20:40},{0:180})
        Line2a=dim_avg_n_Wrap(Line2,0)   ;编号3
    ;底图属性
    wks = gsn_open_wks("png","wincy")
        
        res1                  = True
        ; res1@gsnDraw                 = False
    ; res1@gsnFrame                 = False
        res1@cnFillOn                = True
    res1@cnFillPalette                 ="cmocean_balance"
        res1@cnLevelSelectionMode         = "AUTOMATICLEVELS"
        res1@cnMaxLevelValF                          = 100
        res1@cnMinLevelValF                          = 100
        res1@cnLevelSpacingF                 = 10
        res1@cnLinesOn                = False
    res1@mpMinLatF                                 = -20.
        res1@mpMaxLatF                                = 40.
        res1@mpMinLonF                                 = 0.
        res1@mpMaxLonF                                 = 180.
        res1@mpCenterLonF                         = 90.
        res1@gsnLeftString                        = "(a)NW Pattern"
        res1@gsnLeftStringFontHeightF=0.02
        res1@gsnRightString                        = "500hPa"
        res1@gsnRightStringFontHeightF=0.02
        res1@gsnAddCyclic            =False
        
        
        res2                  = True
        ; res2@gsnDraw                 = False
    ; res2@gsnFrame                 = False
        res2@cnFillOn                = True
    res2@cnFillPalette                 ="cmocean_balance"
        res2@cnLevelSelectionMode         = "AUTOMATICLEVELS"
        res2@cnMaxLevelValF                          = 100
        res2@cnMinLevelValF                          = 100
        res2@cnLevelSpacingF                 = 10
        res2@cnLinesOn                = False
    res2@mpMinLatF                                 = -20.
        res2@mpMaxLatF                                = 40.
        res2@mpMinLonF                                 = 0.
        res2@mpMaxLonF                                 = 180.
        res2@mpCenterLonF                         = 90.
        res2@gsnLeftString                        = "(b)SE Pattern"
        res2@gsnLeftStringFontHeightF=0.02
        res2@gsnRightString                        = "500hPa"
        res2@gsnRightStringFontHeightF=0.02
        res2@gsnAddCyclic            =False
        
        ;划线5880西太副高轮廓属性-----------------------------------------------------------------------
        resp1=True
        ; resp1@gsnDraw                 = False
    ; resp1@gsnFrame                 = False
        resp1@cnFillOn                = False
        resp1@cnLinesOn                = True
        resp1@cnLevelSelectionMode="ExplicitLevels"
        resp1@cnLevels=(/57620/)
        resp1@cnLineColor="Black"
        resp1@gsnAddCyclic            =False
        resp1@cnLineThicknessF = 2.0
        
        resp2=True
        ; resp2@gsnDraw                 = False
    ; resp2@gsnFrame                 = False
        resp2@cnFillOn                = False
        resp2@cnLinesOn                = True
        resp2@cnLevelSelectionMode="ExplicitLevels"
        resp2@cnLevels=(/57620/)
        resp2@cnLineColor="Blue"
        resp2@gsnAddCyclic            =False
        resp2@cnLineThicknessF = 2.0
        
        resp3=True
        ; resp3@gsnDraw                 = False
    ; resp3@gsnFrame                 = False
        resp3@cnFillOn                = False
        resp3@cnLinesOn                = True
        resp3@cnLevelSelectionMode="ExplicitLevels"
        resp3@cnLevels=(/57620/)
        resp3@cnLineColor="Red"
        resp3@gsnAddCyclic            =False
        resp3@cnLineThicknessF = 2.0
        
        ;draw plots
        base0=gsn_csm_contour_map_ce(wks,hgt_dif1,res1)
        base1=gsn_csm_contour_map_ce(wks,hgt_dif2,res2)
        
        
        plot1=gsn_csm_contour(wks,Linea,resp1)
        plot2=gsn_csm_contour(wks,Line1a,resp2)
        plot3=gsn_csm_contour(wks,Line2a,resp3)
        
        overlay(base0,plot1)
        overlay(base0,plot2)
        overlay(base0,plot3)
    draw(base0)
        
        overlay(base1,plot1)
        overlay(base1,plot2)
        overlay(base1,plot3)
        draw(base1)


        
end

line1

line1

base2

base2

base1

base1

line2

line2

line3

line3

评分

参与人数 1金钱 +1 收起 理由
zsuzifan + 1 赞一个!

查看全部评分

密码修改失败请联系微信:mofangbao
 楼主| 发表于 2021-3-9 15:27:07 | 显示全部楼层
这个问题已经解决啦,主要还是对overlay的一些要点不够了解。下面是对overlay的总结:
1.overlay(plotBase,plotOverlay)
plotBase 画填色的变量plotOverlay 画实线或箭头
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-9 15:29:21 | 显示全部楼层
2.overlay 前绘图把 gsnDrawgsnFrame 设定为 False
(我之前没有设置好这个,当时是出不了图的)
3.叠加的图 plotOverlay 不能用 gsn_csm_XXX_map 开头的绘图函数
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-9 15:31:27 | 显示全部楼层
修改结束后的程序可以正常出图,如下所示:
begin
    f=addfile("new_hgt.nc","r");hgt(initial_time0_hours, g0_lat_1, g0_lon_2)
        f1=addfile("hgt.grib","r");;Z_GDS0_ISBL_S123 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
    timeARR    = cd_calendar(f->initial_time0_hours,-5)
    yrARR            = timeARR(:,0)
    monARR            = timeARR(:,1)
        ;底图填色-------------------------------------------------------------------------------------
        ;climate
        hgt=f->hgt(:,{-20:40},{0:180})
        hgta=dim_avg_n_Wrap(hgt,0)
        ;NW Pattern
        timeInd1=ind(yrARR.eq.1987.or.yrARR.eq.1988.or.yrARR.eq.1996.or.yrARR.eq.2010.or.yrARR.eq.2019.or.yrARR.eq.2020)
        hgt1=f->hgt(timeInd1,{-20:40},{0:180})
        hgt1a=dim_avg_n_Wrap(hgt1,0)
        hgt_dif1=hgt1a-hgta  ;117.469  -48.5216
        copy_VarMeta(hgt1a,hgt_dif1)
        ;SE Pattern
        timeInd2=ind(yrARR.eq.1990.or.yrARR.eq.1997.or.yrARR.eq.1999.or.yrARR.eq.2001.or.yrARR.eq.2006.or. \
     yrARR.eq.2012.or.yrARR.eq.2014.or.yrARR.eq.2018)
        hgt2=f->hgt(timeInd2,{-20:40},{0:180})
        hgt2a=dim_avg_n_Wrap(hgt2,0)
        hgt_dif2=hgt2a-hgta    ;67.7029  -86.2909
        copy_VarMeta(hgt2a,hgt_dif2)       
        ;划线5880西太副高轮廓-------------------------------------------------------------------------
    ;climate
        Line=f1->Z_GDS0_ISBL_S123(:,{-20:40},{0:180})
        Linea=dim_avg_n_Wrap(Line,0) ;编号1
        ;NW Pattern
        Line1=f1->Z_GDS0_ISBL_S123(timeInd1,{-20:40},{0:180})
        Line1a=dim_avg_n_Wrap(Line1,0)  ;编号2
        ;SE Pattern
        Line2=f1->Z_GDS0_ISBL_S123(timeInd2,{-20:40},{0:180})
        Line2a=dim_avg_n_Wrap(Line2,0)   ;编号3
    ;底图属性
    wks = gsn_open_wks("png","wincy")
       
        res1                  = True
        res1@gsnDraw                 = False
    res1@gsnFrame                 = False
        res1@cnFillOn                = True
    res1@cnFillPalette                 ="cmocean_balance"
        res1@cnLevelSelectionMode         = "AUTOMATICLEVELS"
        res1@cnMaxLevelValF                          = 100
        res1@cnMinLevelValF                          = 100
        res1@cnLevelSpacingF                 = 10
        res1@cnLinesOn                = False
    res1@mpMinLatF                                 = -20.
        res1@mpMaxLatF                                = 40.
        res1@mpMinLonF                                 = 0.
        res1@mpMaxLonF                                 = 180.
        res1@mpCenterLonF                         = 90.
        res1@gsnLeftString                        = "(a)NW Pattern"
        res1@gsnLeftStringFontHeightF=0.02
        res1@gsnRightString                        = "500hPa"
        res1@gsnRightStringFontHeightF=0.02
        res1@gsnAddCyclic            =False
       
       
        res2                  = True
        res2@gsnDraw                 = False
    res2@gsnFrame                 = False
        res2@cnFillOn                = True
    res2@cnFillPalette                 ="cmocean_balance"
        res2@cnLevelSelectionMode         = "AUTOMATICLEVELS"
        res2@cnMaxLevelValF                          = 100
        res2@cnMinLevelValF                          = 100
        res2@cnLevelSpacingF                 = 10
        res2@cnLinesOn                = False
    res2@mpMinLatF                                 = -20.
        res2@mpMaxLatF                                = 40.
        res2@mpMinLonF                                 = 0.
        res2@mpMaxLonF                                 = 180.
        res2@mpCenterLonF                         = 90.
        res2@gsnLeftString                        = "(b)SE Pattern"
        res2@gsnLeftStringFontHeightF=0.02
        res2@gsnRightString                        = "500hPa"
        res2@gsnRightStringFontHeightF=0.02
        res2@gsnAddCyclic            =False
       
        ;划线5880西太副高轮廓属性-----------------------------------------------------------------------
        resp1=True
        resp1@gsnDraw                 = False
    resp1@gsnFrame                 = False
        resp1@gsnLeftString                        = ""
        resp1@gsnRightString                = ""
        resp1@cnFillOn                = False
        resp1@cnLinesOn                = True
        resp1@cnLevelSelectionMode="ExplicitLevels"
        resp1@cnLevels=(/57624/)
        resp1@cnLineColor="Black"
        resp1@gsnAddCyclic            =False
        resp1@cnLineThicknessF = 5.0
        resp1@cnLineLabelsOn=False
       
        resp2=True
        resp2@gsnLeftString                        = ""
        resp2@gsnRightString                = ""
        resp2@gsnDraw                 = False
    resp2@gsnFrame                 = False
        resp2@cnFillOn                = False
        resp2@cnLinesOn                = True
        resp2@cnLevelSelectionMode="ExplicitLevels"
        resp2@cnLevels=(/57624/)
        resp2@cnLineColor="Blue"
        resp2@gsnAddCyclic            =False
        resp2@cnLineThicknessF = 5.0
        resp2@cnLineLabelsOn=False
       
        resp3=True
        resp3@gsnLeftString                        = ""
        resp3@gsnRightString                = ""
        resp3@gsnDraw                 = False
    resp3@gsnFrame                 = False
        resp3@cnFillOn                = False
        resp3@cnLinesOn                = True
        resp3@cnLevelSelectionMode="ExplicitLevels"
        resp3@cnLevels=(/57624/)
        resp3@cnLineColor="Red"
        resp3@gsnAddCyclic            =False
        resp3@cnLineThicknessF = 5.0
        resp3@cnLineLabelsOn=False
       
        ;draw plots
        ;base0=gsn_csm_contour_map_ce(wks,hgt_dif1,res1)
        base1=gsn_csm_contour_map_ce(wks,hgt_dif2,res2)
       
       
        plot1=gsn_csm_contour(wks,Linea,resp1)
        plot2=gsn_csm_contour(wks,Line1a,resp2)
        plot3=gsn_csm_contour(wks,Line2a,resp3)
       
       
        overlay(base0,plot1)
        overlay(base0,plot2)
        overlay(base0,plot3)
        draw(wks)
   
        overlay(base1,plot1)
        overlay(base1,plot2)
        overlay(base1,plot3)
        draw(wks)
    frame(wks)


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

使用道具 举报

发表于 2021-9-28 16:56:11 | 显示全部楼层
谢谢,刚好overlay不了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

发表于 2023-8-30 17:23:15 | 显示全部楼层
太厉害了,谢谢楼主
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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