爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 1572|回复: 4

[作图] 用NCL画时间高度剖面图时,横纵坐标是反的(感觉图应该旋转90度才对)

[复制链接]

新浪微博达人勋

发表于 2023-7-7 11:27:53 | 显示全部楼层 |阅读模式

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

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

x
用NCL画某一个点的时间-高度剖面图,应该是12个时次、10个层次,但是出的图纵坐标(垂直层次上)却有12个点,横坐标(时间轴上)却只有10个点,就是横纵坐标倒了,而且图感觉也是应该旋转90度才对。脚本和图都在下面,各位大神帮着看看哈,实在找不到问题了,ChatGPT都用上了,也没找到错误。
begin
  ; 读取数据
  cdf = addfile("E:/2023WORK/20230611/20230611.nc","r")
  rh         = short2flt(cdf->r(:,:,{46},{122}))
;关于高度层的设定
  levels        = cdf->level  
  ldims = dimsizes(levels)
  lt=ldims(0)
  lev=ispan(0,lt-1,1)
  print(ldims(0))
  print(levels(0))    ;第一层是200hPa
;关于时间的设定
  times       = cdf->time  
  ndims = dimsizes(times)
  nt=ndims(0)
  taus = ispan(0,nt-1,1)
  ;平滑数据
  smothrh   = smth9(rh, 0.50, -0.25, False)
  ; 设置绘图窗口
  wks = gsn_open_wks("png", "plot")
  ; 设置绘图参数
  res = True
  res@sfXArray = taus(0:nt-1:1)
  res@sfYArray = lev(0:lt-1:1)
  res@tiYAxisString     = "height/(m)"
  res@tmYLMode       = "Explicit" ; Define own tick mark labels.
  res@tmYLValues     = lev(::1)     ; location of explicit labels
  res@tmYLLabels     =  (/"200", "300", "400",  "500", "700", \
                            "850", "925", "950",  "975", "1000"/)
  res@tmXBMode       = "Explicit" ; Define own tick mark labels.
  res@tmXBValues     = taus(::1)       ; location of explicit labels
  res@tmXBLabels     = (/"8:00", "12:00", "20:00",  "Jun11", "08:00", \
                            "12:00", "20:00", "Jun12",  "08:00", "12:00", "20:00", "Jun13"/)

  ; 绘制时间高度剖面图
  plot = gsn_csm_contour(wks,smothrh,res)
  draw(plot)              
  frame(wks)
  end






plot.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2023-7-7 11:30:10 | 显示全部楼层
脚本太长了,删了一些不重要的设置。错误提示:warning:ScalarFieldSetValues: coordinate array sfXArray requires 10 elements: defaulting
warning:ScalarFieldSetValues: coordinate array sfYArray requires 12 elements: defaulting

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

使用道具 举报

新浪微博达人勋

发表于 2023-7-11 04:03:49 | 显示全部楼层
transpose(smothrh)
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-12-21 19:32:35 | 显示全部楼层
我遇到了同样的问题,请问您解决了吗
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2024-1-26 16:42:13 | 显示全部楼层
wangzx 发表于 2023-12-21 19:32
我遇到了同样的问题,请问您解决了吗

begin
  cdf = addfile("E:/2023WORK/20230611/712-715.nc","r")
  ;***********************************************
;关于层次的设定
  levels        = cdf->level  
  ldims = dimsizes(levels)
  lt=ldims(0)
  lev=ispan(0,lt-1,1)
  print(ldims(0))
  print(levels(0))    ;第一层是200hPa
;***********************************************
;关于时间的设定
  times       = cdf->time  
  ndims = dimsizes(times)
  nt=ndims(0)
  taus = ispan(0,nt-1,1)
  print(ndims(0))
  print(times(0))

  gap =1

  ta         = short2flt(cdf->t(:,:,{45},{121.5}))  ;46,122是乌兰浩特市的经纬度
  rh         = short2flt(cdf->r(:,:,{45},{121.5}))
  uu         = short2flt(cdf->u(:,:,{45},{121.5}))
  vv         = short2flt(cdf->v(:,:,{45},{121.5}))
  tt=ta-273.16
  copy_VarMeta(ta, tt)
  name="pou20230713-"
  type="png"
  type@wkWidth = 1700     ;可以通过设置改变图片分辨率
  type@wkHeight = 1700
  outpath="D:/cygwin/home/Administrator/"
  wks = gsn_open_wks(type,outpath+name)
  gsn_define_colormap(wks,"rh")

  rhh=transpose(rh)
  t  =transpose(tt)
  u  =transpose(uu)
  v  =transpose(vv)
  ;***********************************************
  rh_res      = True
  temp_res    = True
  uv_res      = True
;***********************************************
; Here are the resources that rh_res, temp_res, and uv_res share.
;***********************************************
  rh_res              = True
  rh_res@cnSmoothingOn  = True
  rh_res@cnSmoothingDistanceF = 0.005
  rh_res@cnSmoothingTensionF = 0.01
  rh_res@trYReverse   = True     ; Reverse the Y values.;第一层是200hPa,所以要用这个语句倒转Y轴
  rh_res@trXReverse   = True
  rh_res@gsnDraw      = False    ; Don't draw individual plot  不画单独的图层
  rh_res@gsnFrame     = False    ; Don't advance frame.
  rh_res@vpXF         = 0.1    ; x location   X轴左边界的位置
  ;rh_res@vpYF         = 0.90     ; y location   Y轴上边界的位置
  rh_res@vpWidthF     = 0.83      ; width       图片的宽度
  rh_res@vpHeightF    = 0.40     ; height
  rh_res@tmXBLabelFontHeightF = 0.015   ;设置xy轴字体大小
  rh_res@tmYLLabelFontHeightF = 0.015

  temp_res            = rh_res   ; copy shared resources to other lists
  uv_res              = rh_res
;***********************************************
; Relative humidity only resources
;***********************************************
  rh_res@cnFillOn          = True               ; turns on color fill
  rh_res@cnLinesOn         = False
  rh_res@gsnLeftString ="Relative humidity"
  rh_res@gsnLeftStringFontHeightF =0.015
  rh_res@gsnRightString ="%"
  rh_res@gsnRightStringFontHeightF =0.015
  rh_res@cnLevelSelectionMode       = "ExplicitLevels"   ;AutomaticLevels
  rh_res@cnLevels=(/60,70,80,90,95,100/)
  rh_res@cnLineLabelsOn    = False               ; no contour labels
  rh_res@tiMainString      = "Meteogram for Wujiaofeng" ; title
  rh_res@tiMainFontHeightF    = 0.02
  rh_res@lbOrientation       = "Vertical"  ; Default is horizontal
  rh_res@lbLabelFontHeightF      =  0.014                    ;-- increase label font size
  rh_res@lbLabelFontThicknessF   =  1.                       ;-- increase label font thickness
  rh_res@lbRightMarginF=0.7
  rh_res@pmLabelBarOrthogonalPosF = -0.02
  rh_res@sfXArray          = lev(0:lt-1:gap)               ; Define X/Y axes values that
  rh_res@sfYArray          = taus(0:nt-1:gap)
  rh_res@tmYLValues     = lev(0:lt-1:gap)
  rh_res@tmYLMode       = "Explicit"
  rh_res@tmYLLabels     = (/"100", "150","200", "250","300", "400", "500", "600","700","800", \
                            "850","900","925","1000"/)

  rh_res@tmXBValues     = taus(0:nt-1:gap)        ; location of explicit labels
  rh_res@tmXBMode       = "Explicit"
  rh_res@tmXBLabels     = (/"8:00", "11:00", "14:00", "17:00","20:00", "23:00","July13", "05:00", \
                            "8:00", "11:00", "14:00","17:00", "20:00",  "23:00","July14",  "05:00", \
                            "8:00", "11:00", "14:00","17:00", "20:00",  "23:00","July15",  "05:00", \
                            "8:00", "11:00", "14:00","17:00", "20:00", "23:00","July16",  "05:00"/)
  rh_res@tmXBLabelAngleF      = 90.            ; change label angle

  ;***********************************************
; Temperature only resources
;***********************************************
  temp_res@sfXArray          = lev(0:lt-1:gap)               ; Define X/Y axes values that
  temp_res@sfYArray          = taus(0:nt-1:gap)      
  temp_res@cnLineLabelsOn  = True    ; no contour labels
  temp_res@cnLineThicknessF= 3.0     ; line thickness
  temp_res@cnLineColor     = "Red"   ; color of contour lines
;***********************************************
; wind barb only resources
;***********************************************
  uv_res@vfXArray          = lev(0:lt-1:gap)               ; Define X/Y axes values that
  uv_res@vfYArray          = taus(0:nt-1:gap)      
  uv_res@vcRefAnnoOn         = False      ; turns off the ref vector
  uv_res@vcRefLengthF        = 0.040      ; set length of ref vector
  uv_res@vcGlyphStyle        = "WindBarb" ; turn on windbarbs
  uv_res@vcMonoWindBarbColor = True       ; to color the windbarbs with
                                          ; respect to speed use False
  uv_res@vcMapDirection = False               ; needed to disassociate the coordinate plane from the wind barbs
  uv_res@vcWindBarbLineThicknessF=4
  uv_res@vcRefLengthF=0.03
;********************************************************
; three of the above plots become one overlay plot
;********************************************************
  rhfill    = gsn_csm_contour(wks,rhh,rh_res)
  templine  = gsn_contour(wks,t,temp_res)
  windlayer = gsn_vector(wks,u*2.5,v*2.5,uv_res)
  overlay(rhfill,templine)   ; result is templine over rhfill
  overlay(rhfill,windlayer)
  draw(rhfill)               ; draw this overlay result

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

使用道具 举报

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

本版积分规则

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

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

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