爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1013|回复: 0

[作图] ncl绘制xy图

[复制链接]
发表于 2019-4-8 18:30:08 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 刀客白刃 于 2019-4-9 09:53 编辑



load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
begin
;read data


tlevl=16


f1=addfile("/home/public2/data/18qinc/lanzhouandxinqu/wrfout_d03_2014-01-09_00:00:00","r")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Longitude1 = 103.64
Latitude1  = 36.12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Longitude2 = 103.67
Latitude2 = 36.58
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
th11=wrf_user_getvar(f1,"T2",-1)


res0 = True
res0@returnInt = True                                       ; False : return real values, True: return interger values
wks   = gsn_open_wks ("png","T2")                 ; chu tu wen jian ming


point = wrf_user_ll_to_ij(f1,Longitude1,Latitude1,res0)     ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)
x = point(0)
y = point(1)
print("X location is: " + x)            ; print the value of X at the screen
print("Y location is: " + y)            ; print the value of Y at the screen
t1=new((24),"float")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


point1 = wrf_user_ll_to_ij(f1,Longitude2,Latitude2,res0)     ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)
x1 = point1(0)
y1 = point1(1)
print("X location is: " + x1)            ; print the value of X at the screen
print("Y location is: " + y1)            ; print the value of Y at the screen
t2=new((24),"float")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
times=wrf_user_list_times(f1)
ntimes=dimsizes(times)
m=ntimes-1


th1=new(ntimes,float)
th2=new(ntimes,float)




do i=0,m,1
th1(i)=avg(th11(i,y-3:y+3,x-3:x+3))
th2(i)=avg(th11(i,y1-10:y1+10,x1-10:x1+10))
end do


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
do it=0,23,1
t1(it)  = dim_avg_n_Wrap(th1(tlevl+it::24),0)-273.15
t2(it)  = dim_avg_n_Wrap(th2(tlevl+it::24),0)-273.15
end do
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print (t1)
print (t2)
a=new((24),"integer")
a=ispan(0,23,1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
res1                   = True                      ; plot mods desired
res1@gsnDraw           = True
res1@gsnFrame          = True
res1@tiMainString      = ""                            ; add title
; res1@tiMainString             = " "               ; add title
res1@tiXAxisString            = "time/h"
;res1@tiMainString = "~S~o~N~C"
res1@tiYAxisString            = "2m temperature(~S~o~N~C)"
res1@tmXTOn                   = True
res1@xyMarkLineMode           = "Lines"
res1@xyLineColor              = "red"
res1@xyLineThicknesses        = 4.0
res1@xyMarkLineModes          = "MarkLines"
res1@xyMarker                 = 5
res1@xyMarkerColors           = 3
res1@tmYLOn                   = True
res1@tmYLLabelsOn             = True
res1@trYMaxF                  = 5
res1@trYMinF                  =-15   
res1@tmYLMode                 = "Manual"
res1@tmYLTickStartF           = -15
res1@tmYLTickEndF             = 5
res1@tmYLTickSpacingF         = 5
res1@tmXBOn                   = True
res1@tmXBLabelsOn             = True
res1@trXMaxF                  = 23
res1@trXMinF                  = 0
res1@tmXBMode                 = "Manual"
res1@tmXBTickStartF           = 0
res1@tmXBTickEndF             = 23
res1@tmXBTickSpacingF         = 4
res1@vpWidthF  = 0.6              ; height and width of plot
res1@vpHeightF = 0.4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  res2                          = True
  res2@gsnDraw                  = False
  res2@gsnFrame                 = False
  res2@tmXTOn                   = True
  res2@xyMarkLineMode           = "Lines"
  res2@xyLineColor              = "blue"
  res2@xyLineThicknesses        = 4.0
  res2@xyMarkLineModes          = "MarkLines"
  res2@xyMarker                 = 6
  res2@xyMarkerColors           = 4
  res2@tmYLOn                   = True
  res2@tmYLLabelsOn             = True
  res2@tmYLMode                 = "Manual"
  res2@trYMaxF                  = 5
  res2@trYMinF                  =-15
  res2@tmYLTickStartF           = -15
  res2@tmYLTickEndF             = 5
  res2@tmYLTickSpacingF         = 5
  res2@trXMaxF                  = 23
  res2@trXMinF                  = 0
  res2@tmXBMode                 = "Manual"
  res2@tmXBTickStartF           = 0
  res2@tmXBTickEndF             = 23
  res2@tmXBTickSpacingF         = 4
  res2@vpWidthF  =0.6               ; height and width of plot
  res2@vpHeightF = 0.4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  res_text1                      = True
  res_text1@txFontHeightF        = 0.015
  res_text1@txJust               = "CenterLeft"
  res_text1@xyMarkLineModes      = "MarkLines"
  res_text1@xyMarker             = 5
  res_text1@xyMarkerColors       = 3


  res_text2                      = True
  res_text2@txFontHeightF        = 0.015
  res_text2@txJust               = "CenterLeft"
  res_text2@xyMarkLineModes      = "MarkLines"
  res_text2@Marker               = 6
  res_text2@xyMarkerColors       = 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  plot1  = gsn_csm_y (wks,t1,res1)
  plot2  = gsn_csm_y (wks,t2,res2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   res_lines                   = True                  ; polyline mods desired
   res_lines@gsLineDashPattern = 0.                    ; solid line
   res_lines@gsLineThicknessF  = 3.                    ; line thicker
   res_lines@gsLineColor       = "red"                 ; line color
   res_lines@gsMarkerIndex     = 5
   res_lines@gsMarkerColor     = 3
   res_lines@gsMarkerSizeF     = 0.15


   xx = (/18,19/)
   yy = (/4,4/)
   dum1 = gsn_add_polyline(wks,plot1,xx,yy,res_lines)  ; add polyline


   res_lines                   = True                  ; polyline mods desired
   res_lines@gsLineDashPattern = 0.                    ; solid line
   res_lines@gsLineThicknessF  = 3.                    ; line thicker
   res_lines@gsLineColor       = "blue"                ; line color
   xx = (/18,19/)
   yy = (/2,2/)
   dum2 = gsn_add_polyline(wks,plot2,xx,yy,res_lines)  ; add polyline
   dum3   = gsn_add_text(wks,plot1,"Main city",19,4,res_text1); add text
   dum4   = gsn_add_text(wks,plot2,"New Area",19,2,res_text2); add text
   ;dum5   = gsn_add_text(wks,plot1,"(a)",281,1150,res_text2); add text


overlay(plot1,plot2)
draw(plot1)
frame(wks)


end

T2.000002.png
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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