爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11120|回复: 5

[作图] 求助,ncl画XYplot两曲线之前的填色图

[复制链接]

新浪微博达人勋

发表于 2018-12-2 20:26:03 | 显示全部楼层 |阅读模式
1金钱
我先提取了RegCM模拟结果的温度数据,并处理成月平均数据,求了月最大最小温度,并将其放在一个nc文件中,在利用ncl官网上的脚本改动后进行画图。
但是图出来就只是一条直线,图例也没有出来,也没有报错信息。
贴出了脚本,求助大家!
;*************************************************************
;This script is XYplot picture of Regcm,
;which about 10years templature of Model-out with time.
;*************************************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;*************************************************************
;*************************************************************
;读取处理好的月平均后的区域平均温度数据。
;*************************************************************

fils1     = systemfunc("ls EIN15ATM??.nc")
fils2     = systemfunc("ls EIN75ATM??.nc")
fils3     = systemfunc("ls ERA40ATM??.nc")
fils4     = systemfunc("ls ICBCATM??.nc")
f1        = addfiles(fils1,"r")
f2        = addfiles(fils2,"r")
f3        = addfiles(fils3,"r")
f4        = addfiles(fils4,"r")
ListSetType(f1,"cat")
ListSetType(f2,"cat")
ListSetType(f3,"cat")
ListSetType(f4,"cat")

  T1             = f1[:]->temp
  T2             = f2[:]->temp
  T3             = f3[:]->temp
  T4             = f4[:]->temp
  T1_MIN         = f1[:]->t_min
  T1_MAX         = f1[:]->t_max
  T2_MIN         = f2[:]->t_min
  T2_MAX         = f2[:]->t_max
  T3_MIN         = f3[:]->t_min
  T3_MAX         = f3[:]->t_max
  T4_MIN         = f4[:]->t_min
  T4_MAX         = f4[:]->t_max

  nmonths  = 96
  times    = ispan(0,95,1)

gavan         = new((/10,nmonths/),float)
gavan(0,:)    = T1-avg(T1)
gavan(1,:)    = T2-avg(T2)
gavan(2,:)    = T3-avg(T3)
gavan(3,:)    = T4-avg(T4)
gavan(4,:)    = T1_MIN-avg(T1)
gavan(5,:)    = T1_MAX-avg(T1)
gavan(6,:)    = T2_MIN-avg(T2)
gavan(7,:)    = T2_MAX-avg(T2)
gavan(8,:)    = T3_MIN-avg(T3)
gavan(9,:)    = T3_MAX-avg(T3)
  
gavan!0      = "ensembles"
gavan!1      = "time"
gavan&time   = (/times/)
gavan&ensembles = (/0,1,2,3,4,5,6,7,8,9/)
;*********************************************************
;开始画图
;**********************************************************
  wks = gsn_open_wks("x11","templature-late8yr")            

  res                    = True            
  res@gsnDraw            = False            
  res@gsnFrame           = False            
  res@vpHeightF          = 0.4              
  res@vpWidthF           = 0.7

  res@trYMaxF            = 10
  res@trYMinF            = -10
  res@trXMinF            = 1992            
  res@trXMaxF            = 1999

  res@xyMonoLineColor    = False            
  res@xyLineColors       = (/"Black","Red","Blue","Yellow"/)
  res@xyLineThicknesses  = (/3.,3.,3.,4./)      
  res@xyDashPatterns     = (/0.,0.,0.,0./)      

  res@tiYAxisString  = "~F35~J~F~C"         
  res@txFontHeightF  = 0.0195         
  
  top_plot = gsn_csm_xy (wks,times,gavan(0:3,:),res)     

;*******************************************************************************
;将模拟结果中最大值、最小值曲线之间的部分填色。
;*******************************************************************************
  res@gsnXYFillColors = "LightPink"
  res@xyLineColor     = -1                           
  bot_plot  = gsn_csm_xy (wks,times,gavan(4:5,:),res)   

  res@gsnXYFillColors = "LightBlue"      
  res@xyLineColor     = -1                           
  mid1_plot  = gsn_csm_xy (wks,times,gavan(6:7,:),res)  

  res@gsnXYFillColors = "LightYellow"
  res@xyLineColor     = -1                           
  mid2_plot  = gsn_csm_xy (wks,times,gavan(8:9,:),res)  

  overlay(bot_plot,mid1_plot)
  overlay(bot_plot,mid2_plot)
  overlay(bot_plot,top_plot)

;***********************************************************************************   
; 创建图例
;***********************************************************************************
  res_text                    = True                  
  res_text@txFontHeightF      = 0.015                 
  res_text@txJust             = "TopLeft"            

  res_lines                   = True                  
  res_lines@gsLineDashPattern = 0.                  
  res_lines@gsLineThicknessF  = 5.                  
  res_lines@gsLineColor       = "black"               
  xx = (/1992,1999/)
  yy = (/0.705,0.705/)
  dum1 = gsn_add_polyline(wks,bot_plot,xx,yy,res_lines)            
  dum2 = gsn_add_text(wks,bot_plot,"Obs",1910,0.705,res_text)
  
  yy = (/0.79,0.79/)
  res_lines@gsLineColor       = "red"                              
  dum3 = gsn_add_polyline(wks,bot_plot,xx,yy,res_lines)               
  dum4 = gsn_add_text(wks,bot_plot,"IN15",1910,0.79,res_text)      

  yy = (/0.875,0.875/)
  res_lines@gsLineColor       = "blue"                           
  dum5 = gsn_add_polyline(wks,bot_plot,xx,yy,res_lines)              
  dum6 = gsn_add_text(wks,bot_plot,"IN75",1910,0.875,res_text)      

  yy = (/0.935,0.935/)
  res_lines@gsLineColor       = "yellow"                           
  dum7 = gsn_add_polyline(wks,bot_plot,xx,yy,res_lines)               
  dum8 = gsn_add_text(wks,bot_plot,"RA25",1910,0.936,res_text)     

;*************************************************************
;编辑标题
;*************************************************************
  res_text               = True
  res_text@txFontHeightF = 0.03                    
  txid_top = gsn_create_text(wks, "Regional Climate Model", res_text)

  amres                  = True
  amres@amJust           = "BottomCenter"
  amres@amParallelPosF   =  0.0   
  amres@amOrthogonalPosF = -0.72   
  annoid_top = gsn_add_annotation(bot_plot, txid_top, amres)

  res_text@txFontHeightF = 0.02                       
  txid_mid = gsn_create_text(wks, "Regional Temperature Anomalies",res_text)

  amres@amOrthogonalPosF = -0.62
  annoid_mid = gsn_add_annotation(bot_plot, txid_mid, amres)

  res_text@txFontHeightF = 0.015                  
  txid_bot = gsn_create_text(wks,"from 1992-1999 average",res_text)

  amres@amOrthogonalPosF = -0.55  ;
  annoid_bot = gsn_add_annotation(bot_plot, txid_bot, amres)
  
  pres = True
  maximize_output(wks,pres)
end  



QQ图片20181124195708.png
1543753332(1).png
QQ图片20181124195708.png
1543753332(1).png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2018-12-2 20:28:19 | 显示全部楼层
第一张图是我想要的效果,后面一张图是出来的图,理想很丰满,现实很骨感
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2018-12-5 16:58:58 | 显示全部楼层
你把 delete(res@xyLineColors )加到top_plot 和bot_plot 之间试试。
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2018-12-6 08:57:03 | 显示全部楼层
代码太长没看
但是你给的例图和你的标题“两曲线之前的填色图”不符,例图那颜色是
errorbar
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2018-12-8 11:39:02 | 显示全部楼层
数据也不多   输出来看看数据是否类似图一的锯齿状的   是不是提取的不对?
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2018-12-8 14:44:29 | 显示全部楼层
问题已解决,是因为res@trXMaxF, res@trXMinF 设置错了,应该设置成0到95,在使用
  res@tmXBMode           = "Explicit"
  res@tmXBValues         = (/11,23,35,47,59,71,83,95/)
  res@tmXBLabels         = (/"1992","1993","1994","1995","1996","1997","1998","1999"/)
修改X轴坐标,就可以出来好看的折线图填色图了。
  
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

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

本版积分规则

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

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

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