「已注销」 2024-04-19 11:57 采纳率: 34.8%
浏览 23
已结题

ncl画图打点打不上怎么解决,报错很多

ncl打点打不上位置为(91,29),怎么解决


begin 
f=addfile("uvh.nc","r")  
time1=f->time
tim1=cd_calendar(time1,3)
;print(tim1)
a=ind(tim1.eq.2023021100)
b=ind(tim1.eq.2023021102)
c=ind(tim1.eq.2023021104)
d=ind(tim1.eq.2023021106)
hgt1=short2flt(f->z(a,{200},:,:)) 
hgt2=short2flt(f->z(b,{200},:,:)) 
hgt3=short2flt(f->z(c,{200},:,:)) 
hgt4=short2flt(f->z(d,{200},:,:)) 
;min_value=min(hgt1)
;max_value=max(hgt1)
;print(min_value)
;print(max_value)
uwnd1=short2flt(f->u(a,{200},:,:))
uwnd2=short2flt(f->u(b,{200},:,:))
uwnd3=short2flt(f->u(c,{200},:,:))
uwnd4=short2flt(f->u(d,{200},:,:))

vwnd1=short2flt(f->v(a,{200},:,:))
vwnd2=short2flt(f->v(b,{200},:,:))
vwnd3=short2flt(f->v(c,{200},:,:))
vwnd4=short2flt(f->v(d,{200},:,:))

wind1=sqrt(uwnd1*uwnd1+vwnd1*vwnd1)
wind2=sqrt(uwnd2*uwnd2+vwnd2*vwnd2)
wind3=sqrt(uwnd3*uwnd3+vwnd3*vwnd3)
wind4=sqrt(uwnd4*uwnd4+vwnd4*vwnd4)
copy_VarCoords(uwnd1,wind1)
copy_VarCoords(uwnd2,wind2)
copy_VarCoords(uwnd3,wind3)
copy_VarCoords(uwnd4,wind4)
;umin=min(uwnd1)
;umax=max(uwnd1)
;print(umin)
;print(umax)

;vmin=min(vwnd1)
;vmax=max(vwnd1)
;print(vmax)
;print(vmin)

wks=gsn_open_wks("png","200hw")
gsn_define_colormap(wks,"WhiteBlueGreenYellowRed")
plot=new(4,graphic)
res0=True
res0@gsnDraw=False   ;暂不绘制
res0@gsnFrame=False  ;暂不翻页
res0@gsnAddCyclic=False ;数据没有覆盖整个地球
res0@gsnLeftString=""  
res0@gsnRightString=""
res0@mpFillOn=False;填色地图
res0@mpOutlineOn=True;绘制陆地边界线
res0@mpDataSetName="Earth..4"
res0@mpDataBaseVersion="MediumRes" 
res0@mpAreaMaskingOn=True
res0@mpMaskAreaSpecifiers=(/"China"/)
res0@mpOutlineSpecifiers=(/"China","China:Provinces"/)
res0@mpMinLonF=70
res0@mpMaxLonF=130
res0@mpMinLatF=15
res0@mpMaxLatF=55
res0@tmXBMode="Explicit" ;手动设置x轴标签
res0@tmXBValues=(/70,80,90,100,110,120,130/) ;x轴坐标
res0@tmXBLabels=(/"70~S~o~N~E","80~S~o~N~E","90~S~o~N~E","100~S~o~N~E","110~S~o~N~E","120~S~o~N~E","130~S~o~N~E"/) 
res0@tmYLMode="Explicit" ;手动设置y轴标签
res0@tmYLValues=(/15,25,35,45,55/) ;y轴坐标
res0@tmYLLabels=(/"15~S~o~N~N","25~S~o~N~N","35~S~o~N~N","45~S~o~N~N","55~S~o~N~N"/)

res0@cnFillOn=True
res0@cnLinesOn = False
res0@cnLevelSelectionMode="ManualLevels"
res0@cnMinLevelValF=30  ;高空急流区域
res0@cnMaxLevelValF=100
res0@cnLevelSpacingF=10
rese=True
rese@gsMarkerSizeF=0.5
rese@gsMarkerIndex=16 
rese@gsMarkerColor="black" 
rese@gsMarkerThicknessF=1 
plot(0)=gsn_add_polymarker(wks,plot(0),91,29,rese)
plot(1)=gsn_add_polymarker(wks,plot(1),91,29,rese)    
plot(2)=gsn_add_polymarker(wks,plot(2),91,29,rese)
plot(3)=gsn_add_polymarker(wks,plot(3),91,29,rese)

pl0=gsn_csm_contour_map_ce(wks,wind1,res0)
pl1=gsn_csm_contour_map_ce(wks,wind2,res0)
pl2=gsn_csm_contour_map_ce(wks,wind3,res0)
pl3=gsn_csm_contour_map_ce(wks,wind4,res0)
overlay(plot(0),pl0)
overlay(plot(1),pl1)
overlay(plot(2),pl2)
overlay(plot(3),pl3)


res1=True
res1@gsnDraw=False
res1@gsnFrame=False
res1@gsnLeftString=""
res1@gsnRightString=""  
res1@vcGlyphStyle="CurlyVector"
res1@vcRefMagnitudeF=60
res1@vcRefLengthF=0.05 
res1@vcMinDistanceF=0.03       
res1@vcLineArrowColor="blue" 
res1@vcLineArrowThicknessF=3.0
res1@vcLineArrowHeadMaxSizeF=0.01
res1@vcRefAnnoOn=False ;关闭参考箭头 
res1@vcRefAnnoString1On=False
res1@vcRefAnnoString2On=False

res3=res1
res3@gsnCenterString="2023021100"
res3@gsnCenterStringFontHeightF=0.03
res3@gsnCenterStringOrthogonalPosF=0.05
vector1=gsn_csm_vector(wks,uwnd1,vwnd1,res3)

res4=res1
res4@gsnCenterString="2023021102"
res4@gsnCenterStringFontHeightF=0.03
res4@gsnCenterStringOrthogonalPosF=0.05
vector2=gsn_csm_vector(wks,uwnd2,vwnd2,res4)

res5=res1
res5@gsnCenterString="2023021104"
res5@gsnCenterStringFontHeightF=0.03
res5@gsnCenterStringOrthogonalPosF=0.05
vector3=gsn_csm_vector(wks,uwnd3,vwnd3,res5)

res6=res1
res6@gsnCenterString="2023021106"
res6@gsnCenterStringFontHeightF=0.03
res6@gsnCenterStringOrthogonalPosF=0.05
vector4=gsn_csm_vector(wks,uwnd4,vwnd4,res6)
overlay(plot(0),vector1)
overlay(plot(1),vector2)
overlay(plot(2),vector3)
overlay(plot(3),vector4)

res7=True
res7@cnLinesOn=True;绘制等值线
res7@cnLevelSpacingF=1000
res7@cnLineThicknessF=4;等值线粗细
res7@cnLineColor="red";等值线颜色
res7@cnLineLabelsOn=True;绘制等值线标签
res7@gsnLeftString=""
res7@gsnRightString=""
res7@cnInfoLabelOn=False
p0=gsn_csm_contour(wks,hgt1,res7)
p1=gsn_csm_contour(wks,hgt2,res7)
p2=gsn_csm_contour(wks,hgt3,res7)
p3=gsn_csm_contour(wks,hgt4,res7)
overlay(plot(0),p0)
overlay(plot(1),p1)
overlay(plot(2),p2)
overlay(plot(3),p3)



pres=True
pres@tiMainString="300hpa hgt&wind field"
pres@txFontHeight=0.02
pres@gsnPanelCenter=True
pres@gsnPanelLabelBar=True
pres@lbLabelBarOn=False
pres@gsnPanelFigureStrings=(/"(a)","(b)","(c)","(d)"/)
pres@gsnPanelFigureStringsFontHeightF=0.01
gsn_panel(wks,plot,(/2,2/),pres)

end


  • 写回答

3条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2024-04-19 11:57
    关注

    引自免费微信小程序:皆我百晓生

    在您提供的 NCL (NCAR Command Language) 代码中,您尝试在同一个面板上绘制不同时间步长的风场、高度场以及标记特定点(91, 29)。然而,您可能会遇到一些错误,因为您试图在不同的子图(plot(i))上添加相同的标记点。这将导致重叠且可能产生混淆的结果。

    要解决这个问题,您可以考虑以下方法:

    1. 将所有标记点放在一个单独的 plot 对象中。
    2. 在每个子图上只显示对应的风场和高度场,而不是将它们全部叠加在一起。

    这里是修改后的代码:

    begin 
    
    f=addfile("uvh.nc","r")  
    time1=f->time
    tim1=cd_calendar(time1,3)
    a=ind(tim1.eq.2023021100)
    b=ind(tim1.eq.2023021102)
    c=ind(tim1.eq.2023021104)
    d=ind(tim1.eq.2023021106)
    hgt1=short2flt(f->z(a,{200},:,:)) 
    hgt2=short2flt(f->z(b,{200},:,:)) 
    hgt3=short2flt(f->z(c,{200},:,:)) 
    hgt4=short2flt(f->z(d,{200},:,:)) 
    uwnd1=short2flt(f->u(a,{200},:,:))
    uwnd2=short2flt(f->u(b,{200},:,:))
    uwnd3=short2flt(f->u(c,{200},:,:))
    uwnd4=short2flt(f->u(d,{200},:,:))
    
    vwnd1=short2flt(f->v(a,{200},:,:))
    vwnd2=short2flt(f->v(b,{200},:,:))
    vwnd3=short2flt(f->v(c,{200},:,:))
    vwnd4=short2flt(f->v(d,{200},:,:))
    
    wind1=sqrt(uwnd1*uwnd1+vwnd1*vwnd1)
    wind2=sqrt(uwnd2*uwnd2+vwnd2*vwnd2)
    wind3=sqrt(uwnd3*uwnd3+vwnd3*vwnd3)
    wind4=sqrt(uwnd4*uwnd4+vwnd4*vwnd4)
    
    wks=gsn_open_wks("png","200hw")
    gsn_define_colormap(wks,"WhiteBlueGreenYellowRed")
    
    -- Create a plot for markers only
    mark_plot = new(graphic)
    mark_res = True
    mark_res@gsMarkerSizeF=0.5
    mark_res@gsMarkerIndex=16 
    mark_res@gsMarkerColor="black" 
    mark_res@gsMarkerThicknessF=1 
    
    mark_plot = gsn_add_polymarker(wks, mark_plot, 91, 29, mark_res)
    
    -- Define the common map resources
    res0=True
    res0@gsnDraw=False   ;暂不绘制
    res0@gsnFrame=False  ;暂不翻页
    res0@gsnAddCyclic=False ;数据没有覆盖整个地球
    res0@gsnLeftString=""  
    res0@gsnRightString=""
    res0@mpFillOn=False;填色地图
    res0@mpOutlineOn=True;绘制陆地边界线
    res0@mpDataSetName="Earth..4"
    res0@mpDataBaseVersion="MediumRes" 
    res0@mpAreaMaskingOn=True
    res0@mpMaskAreaSpecifiers=(/"China"/)
    res0@mpOutlineSpecifiers=(/"China","China:Provinces"/)
    res0@mpMinLonF=70
    res0@mpMaxLonF=130
    res0@mpMinLatF=15
    res0@mpMaxLatF=55
    res0@tmXBMode="Explicit" ;手动设置x轴标签
    res0@tmXBValues=(/70,80,90,100,110,120,130/) ;x轴坐标
    res0@tmXBLabels=(/"70~S~o~N~E","80~S~o~N~E","90~S~o~N~E","100~S~o~N~E","110~S~o~N~E","120~S~o~N~E","130~S~o~N~E"/) 
    res0@tmYLMode="Explicit" ;手动设置y轴标签
    res0@tmYLValues=(/15,25,35,45,55/) ;y轴坐标
    res0@tmYLLabels=(/"15~S~o~N~N","25~S~o~N~N","35~S~o~N~N","45~S~o~N~N","55~S~o~N~N"/)
    
    -- Plot wind and height fields for each time step
    plot(0)=gsn_csm_contour_map_ce(wks,wind1,res0)
    plot(0)=gsn_add_polymarker(wks,plot(0),mark_plot)
    p0=gsn_csm_contour(wks,hgt1,res0)
    overlay(plot(0),p0)
    
    plot(1)=gsn_csm_contour_map_ce(wks,wind2,res0)
    plot(1)=gsn_add_polymarker(wks,plot(1),mark_plot)
    p1=gsn_csm_contour(wks,hgt2,res0)
    overlay(plot(1),p1)
    
    plot(2)=gsn_csm_contour_map_ce(wks,wind3,res0)
    plot(2)=gsn_add_polymarker(wks,plot(2),mark_plot)
    p2=gsn_csm_contour(wks,hgt3,res0)
    overlay(plot(2),p2)
    
    plot(3)=gsn_csm_contour_map_ce(wks,wind4,res0)
    plot(3)=gsn_add_polymarker(wks,plot(3),mark_plot)
    p3=gsn_csm_contour(wks,hgt4,res0)
    overlay(plot(3),p3)
    
    res1=True
    res1@gsnDraw=False
    res1@gsnFrame=False
    res1@gsnLeftString=""
    res1@gsnRightString=""  
    res1@vcGlyphStyle="CurlyVector"
    res1@vcRefMagnitudeF=60
    res1@vcRefLengthF=0.05 
    res1@vcMinDistanceF=0.03       
    res1@vcLineArrowColor="blue" 
    res1@vcLineArrowThicknessF=3.0
    res1@vcLineArrowHeadMaxSizeF=0.01
    res1@vcRefAnnoOn=False ;关闭参考箭头 
    res1@vcRefAnnoString1On=False
    res1@vcRefAnnoString2On=False
    
    res3=res1
    res3@gsnCenterString="2023021100"
    res3@gsnCenterStringFontHeightF=0.03
    res3@gsnCenterStringOrthogonalPosF=0.05
    vector1=gsn_csm_vector(wks,uwnd1,vwnd1,res3)
    
    res4=res1
    res4@gsnCenterString="2023021102"
    res4@gsnCenterStringFontHeightF=0.03
    res4@gsnCenterStringOrthogonalPosF=0.05
    vector2=gsn_csm_vector(wks,uwnd2,vwnd2,res4)
    
    res5=res1
    res5@gsnCenterString="2023021104"
    res5@gsnCenterStringFontHeightF=0.03
    res5@gsnCenterStringOrthogonalPosF=0.05
    vector3=gsn_csm_vector(wks,uwnd3,vwnd3,res5)
    
    res6=res1
    res6@gsnCenterString="2023021106"
    res6@gsnCenterStringFontHeightF=0.03
    res6@gsnCenterStringOrthogonalPosF=0.05
    vector4=gsn_csm_vector(wks,uwnd4,vwnd4,res6)
    
    overlay(plot(0),vector1)
    overlay(plot(1),vector2)
    overlay(plot(2),vector3)
    overlay(plot(3),vector4)
    
    pres=True
    pres@tiMainString="300hpa hgt&wind field"
    pres@txFontHeight=0.02
    pres@gsnPanelCenter=True
    pres@gsnPanelLabelBar=True
    pres@lbLabelBarOn=False
    pres@gsnPanelFigureStrings=(/"(a)","(b)","(c)","(d)"/)
    pres@gsnPanelFigureStringsFontHeightF=0.01
    gsn_panel(wks,plot,(/2,2/
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月19日
  • 创建了问题 4月19日