爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6818|回复: 4

gsn_csm_xy怎么改X轴的坐标

[复制链接]
发表于 2016-8-22 22:29:14 | 显示全部楼层 |阅读模式

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

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

x
gsn_csm_xy(wks,time2,data1, res),time2明明用的是20151025:20151120的时间坐标,怎么变这样
77772.png
密码修改失败请联系微信:mofangbao
发表于 2016-8-23 08:15:36 | 显示全部楼层
是不是可以缩小X坐标轴的范围,限定在数据的20151025:20151120范围应该就好了
密码修改失败请联系微信:mofangbao
发表于 2016-8-23 08:52:05 | 显示全部楼层
脚本呢?{:5_275:}{:5_275:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

发表于 2020-6-8 09:32:42 | 显示全部楼层
请问楼主有没有解决,我也遇到了这个问题
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

发表于 2020-6-8 10:35:09 | 显示全部楼层
本帖最后由 liweier123 于 2020-6-8 10:39 编辑
  1. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"   
  2. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
  3. load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
  4. load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/time_axis_labels.ncl"

  5. ;----------------------------------------------------------------------
  6. ; Converts YYYYMM time to "days since" time.
  7. ;----------------------------------------------------------------------
  8. function yyyymm_to_time(time)
  9. local ntime, stime, year, month, day, hour, minute, second, units
  10. begin
  11.   ntime  = dimsizes(time)
  12.   stime  = tostring(time)
  13.   year   = toint(str_get_cols(stime,0,3))
  14.   month  = toint(str_get_cols(stime,4,5))
  15.   day    = new(ntime,integer)
  16.   hour   = new(ntime,integer)
  17.   minute = new(ntime,integer)
  18.   second = new(ntime,double)

  19. ;----------------------------------------------------------------------
  20. ; Note: you may need to change the day, hour, minute values depending
  21. ; on your definition of "YYYYMM".  Is this the first day and the
  22. ; first hour of the month? Is it the middle of the month?
  23. ;----------------------------------------------------------------------
  24.   day    = 1
  25.   hour   = 0
  26.   minute = 0
  27.   second = 0.d
  28.   units  = "days since " + min(year) + "-01-01 00:00"

  29.   newtime = cd_inv_calendar(year,month,day,hour,minute,second,units,0)

  30.   return(newtime)
  31. end
  32. ;----------------------------------------------------------------------
  33. ; Main code
  34. ;----------------------------------------------------------------------
  35. begin
  36.   shpname = "/cygdrive/g/Tibet/add_TP/DBATP_Line.shp"
  37.   ;afiles  =  systemfunc("ls /cygdrive/g/Tibet/cloudsat/cloud-height/height*.nc")
  38.   files  =  systemfunc("ls  /cygdrive/g/Tibet/cloudsat/data/height_monthly*.nc")
  39.       f  =  addfiles(files, "r")
  40. ListSetType(f, "cat")
  41. ;printVarSummary(f)
  42.     data = f[:]->valavg_monthly
  43. ;printVarSummary(data)
  44. dims = dimsizes(data)
  45. ntim = dims(0)
  46. time = data&time
  47. ;time!0     = "time"
  48. ;time@units = "YYYYMM"
  49. ;print(time)
  50. ; convert integer YYYYMM to float
  51. ;timeF = yyyymm_to_yyyyfrac(time,0)
  52. ;data&time := timeF
  53.   latS  = 25.0
  54.   latN  = 40.0
  55.   lonL  = 70.0
  56.   lonR  = 105.0
  57. ;========================================  余弦加权
  58. lat     = data&lat
  59. clat    = sqrt(cos(lat*0.01745329))
  60. CLAT    = conform(data, clat, 1)
  61. dataw   = data*CLAT
  62. copy_VarCoords(data, dataw)
  63. ;printVarSummary(dataw)
  64. ;======================================== 对加权数据进行EOFs分解并显著性检验
  65. neof    = 3
  66. optEOF  = True
  67. optEOF@jopt = 0                              ;默认值,计算使用协方差矩阵
  68. optETS  = False
  69. eof     = eofunc_n_Wrap(dataw, neof, optEOF, 0)
  70. eof     = smth9_Wrap(eof, 0.5, 0.5, True)
  71. eof_ts  = eofunc_ts_n_Wrap(dataw, eof, optETS, 0)
  72. printVarSummary(eof)                         ; examine EOF variables
  73. printVarSummary(eof_ts)
  74. eof_ts  = dim_standardize_n_Wrap(eof_ts, 0, 1);标准化时间序列 0为样本标准差即N-1 1为进行标准化的维度
  75. pcvar   = eof@pcvar                           ;获取方差贡献属性项
  76. prinfo  = True
  77. sig_ev  = eofunc_north(eof@eval, ntim, prinfo)  ;差异显著性
  78. ;======================================== 定义时间序列eof_ts的属性
  79. eof_ts!0    = "eofs"
  80. ;eof_ts!1    = "time"
  81. eof_ts&eofs = (/1,2,3/)                       ;三个模态
  82. ;eof_ts&time = year
  83. ;print(eof_ts(0,:))
  84. ;============================================================================
  85. wks     = gsn_open_wks("png", "EOF_MaxdBZ_height_month_pinghua-07-10")
  86. stringw  = (/"(a)","(b)","(c)","(d)","(e)","(f)"/)
  87. ploteof = new ( 6, "graphic")
  88. ;=================================================;
  89. ;空间场相关设置
  90. ;=================================================;
  91.    res                      = True                ; contour plots
  92.    res@gsnDraw              = False
  93.    res@gsnFrame             = False
  94.    res@gsnLeftString        = ""
  95.    res@gsnRightString       = ""
  96.    res@cnFillOn             = True                ; turn on color
  97.    res@cnFillMode           = "RasterFill"        ; turn on raster mode
  98.    res@cnLinesOn            = False               ; turn off contour lines
  99.    res@cnLineLabelsOn       = False
  100.    res@cnInfoLabelOn        = False
  101.    res@cnFillPalette        = "BlWhRe"   ; specify colormap
  102.    res@mpShapeMode          = "FreeAspect"
  103.    res@vpHeightF            = 0.3
  104.    res@vpWidthF             = 0.6
  105.    res@gsnAddCyclic         = False                ; force cyclic value
  106.    res@lbLabelBarOn         = False               ; turn off individual lb's
  107.    res@mpFillOn             = False
  108.    res@mpMinLatF            = latS                 ; range to zoom in on
  109.    res@mpMaxLatF            = latN
  110.    res@mpMinLonF            = lonL  
  111.    res@mpMaxLonF            = lonR
  112.    res@tmXBLabelFontHeightF = 0.02
  113.    res@tmYLLabelFontHeightF = 0.02
  114.    res@gsnLeftStringFontHeightF  = 0.02
  115.    res@gsnRightStringFontHeightF = 0.02
  116.    symMinMaxPlt(eof, 40, False, res)              ; 设置几种颜色

  117.    do n=0,2
  118.       res@gsnLeftString     = stringw(n)+"EOF"+(n+1)
  119.       res@gsnRightString    = sprintf("%5.1f", pcvar(n)) +"%"
  120.       ploteof(n) = gsn_csm_contour_map(wks,eof(n,:,:),res)
  121.    end do
  122.       tpres                  =True
  123.       tpres@gsLineColor      = "black"     ;设置廓线颜色
  124.       tpres@gsLineThicknessF = 3              ;设置廓线宽度
  125.       poly0=gsn_add_shapefile_polylines(wks,ploteof(0),shpname,tpres)        ;plot为底图
  126.       poly1=gsn_add_shapefile_polylines(wks,ploteof(1),shpname,tpres)
  127.       poly2=gsn_add_shapefile_polylines(wks,ploteof(2),shpname,tpres)


  128. ;===========================================
  129. ; 时间场相关设置
  130. ;===========================================
  131. ;---Convert the time values and reassign as x's time coordinate array
  132. ;  newtime = yyyymm_to_time(time)
  133. ;  eof_ts&time  := newtime
  134. ;  printVarSummary(eof_ts)

  135.    rts           = True
  136.    rts@gsnDraw   = False       ; don't draw yet
  137.    rts@gsnFrame  = False       ; don't advance frame yet
  138. ;   rts@gsnScale  = True
  139.    ;rts@tmXBFormat= "f"         ; no unnessary decimal pts

  140.    rts@vpHeightF = 0.40        ; Changes the aspect ratio
  141.    rts@vpWidthF  = 0.6
  142.    ;rts@vpXF      = 0.20        ; change start locations
  143.    ;rts@vpYF      = 0.80        ; the plot

  144.    rts@gsnYRefLine           = 0.              ; reference line
  145. ;   rts@gsnXYBarChart         = True            ; create bar chart   
  146.    rts@gsnAboveYRefLineColor = "red"           ; above ref line fill red
  147.    rts@gsnBelowYRefLineColor = "blue"          ; below ref line fill blue

  148.    rts@trXMinF   = min(time)   
  149.    rts@trXMaxF   = max(time)      ; nicer end bound
  150.    rts@tiXAxisString = "Time"
  151.    rts@tiYAxisString = ""
  152. ;   rts@tmXBMode      = "Explicit"
  153. ;   rts@tmXBValues    = time(::12)
  154. ;   rts@tmXBLabels    = (/"Jan ~C~2007","Jan ~C~2008","Jan ~C~2009","Jan ~C~2010"/)
  155.    rts@tmXBLabelFontHeightF = 0.02
  156.    rts@tmYLLabelFontHeightF = 0.02
  157.    res@tmLabelAutoStride    = True                    ; nice stride on labels
  158.    rts@gsnLeftStringFontHeightF = 0.02
  159. ;---Set resources necessary to nicely format X axis
  160. ;  restick           = True
  161. ;  restick@ttmFormat = "%c%Y"              ; Jan 2010, Feb 2010, etc.
  162.   ;time_axis_labels(newtime,rts,restick)

  163.    do n=0,2
  164.       rts@gsnLeftString  = stringw(n+3)+"PC"+(n+1)
  165.       ploteof(n+3) = gsn_csm_xy(wks,time,eof_ts(n,:),rts)
  166.    end do

  167.    resP                     = True                ; panel plots
  168.    resP@gsnMaximize         = True                ; large format
  169.    resP@gsnPanelLabelBar    = True                ; add common colorbar
  170.    resP@gsnPaperOrientation = "portrait"          ; force portrait [landscape]
  171.    resP@amJust              = "TopLeft"
  172.    gsn_panel(wks,ploteof,(/2,3/),resP)        ; draw all 'neof' as one plot

  173.    end

复制代码

图只是eof时间序列,子程序试过也画不出来
Snipaste_2020-06-08_10-34-03.png
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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