爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6639|回复: 3

[作图] ncl画柱状图(bar chart)正负值颜色设置问题

[复制链接]
发表于 2019-12-7 20:51:42 | 显示全部楼层 |阅读模式

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

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

x
第一次发帖,如果有问题欢迎指正!
我在做完EOF分解后,画PC时间序列时,设置了基准线及正负的颜色,但出图后发现红蓝色柱状图的上方好像叠加了一层黑色的图,而且也没有和红蓝的序列完全重合,不知道哪里出了问题,求助一下大家!
以下是这部分的脚本:

;*******************************************
; time series (principal component) plot
;*******************************************
rts                                    = True
rts@gsnDraw                     = False
rts@gsnFrame                   = False
; these four resources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.
  rts@vpHeightF                  = 0.40        ; Changes the aspect ratio
  rts@vpWidthF                   = 0.85
  rts@vpXF                         = 0.10        ; change start locations
  rts@vpYF                         = 0.75        ; the plot

rts@gsnXYBarChart            = True
rts@gsnYRefLine                = 0.0
rts@gsnAboveYRefLineColor      = "Red"
rts@gsnBelowYRefLineColor      = "Blue"

  tt                                     = fspan(1,1428,1428)
  rts@gsnLeftString              = "EOF "+1
  rts@gsnRightString            = sprintf("%5.1f",eof@pcvar(0)) +"%"
  plot2                                = gsn_csm_xy (wks2,tt,eof_ts(0,:),rts)



密码修改失败请联系微信:mofangbao
 楼主| 发表于 2019-12-7 20:54:57 | 显示全部楼层
图是这样的
pdo3.000002.png
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-7 21:04:59 | 显示全部楼层
这是全部的脚本

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin


;=========================提取数据========================

  filename      = "/cygdrive/E/Fudan_University/data/sst.mon.mean.nc"
  f                 = addfile(filename, "r")
  time0          = f->time
  lat              = f->lat({20:70})
  lon             = f->lon({100:260})


  time          = cd_calendar(time0, -5)
  yr             = time(:,0)
  mon          = time(:,1)

  iYYYY         = ind(yr.ge.1900 .and. yr.le.2018)
  sst             = f->sst(iYYYY,{20:70},{100:260})

  nlat           = dimsizes(lat)
  nlon          = dimsizes(lon)
  ntime        = dimsizes(sst&time)

  xClm   = clmMonTLL(sst)                             ; (12,lat,lon)
; printVarSummary(xClm)

  xAnom  = calcMonAnomTLL ( sst, xClm)                ; (time, lat,lon)
; printVarSummary(xAnom)

  xaave  = wgt_areaave_Wrap(xAnom, 1.0, 1.0, 0)
  copy_VarCoords(xAnom(:,0,0), xaave)
  xAnom1 = xAnom-conform(xAnom, xaave, 0)
  copy_VarCoords(xAnom, xAnom1)
; printVarSummary(xaave)
;  printVarSummary(xAnom1)
;  printMinMax(xAnom, True)




;*******************************************
;  EOF
;*******************************************
  neof               = 2
  optEOF           = True      
  optEOF@jopt   = 0   ; This is the default; most commonly used; no need to specify.
  optETS           = False

; =================================================================
; Reorder (lat,lon,time) the *weighted* input data
; Access the area of interest via coordinate subscripting
; =================================================================
  rad    = 4.*atan(1.)/180.
  clat   = lat(:)
  clat   = sqrt( cos(rad*clat) )
  x1     = xAnom1(:,:,:)
  x      = x1*conform(x1, clat, 1)
  copy_VarCoords(x1, x)
; printVarSummary(x)


  X      = x(lat|:,lon|:,time|:)              ; Space x Time
  
  eof    = eofunc_Wrap( X, neof, optEOF)
  eof    = -1*eof  

  eof_ts = eofunc_ts_Wrap( X, eof, False)
  eof_ts = dim_standardize_n( eof_ts, 0, 1)      ; normalize

  eof_regres = eof                               ; create an array w meta data
  do ne = 0,neof-1
     eof_regres(ne,:,:) = (/ regCoef(eof_ts(ne,:), xAnom1(lat|:,lon|:,time|:)) /)
  end do


  ; yyyymm = cd_calendar(eof_ts&time,-2)/100
  ; year       = yyyymm/100

; printVarSummary(eof)
; printVarSummary(eof_ts)


;*******************************************
;  plots
;*******************************************
  wksname1                            = "/cygdrive/E/Fudan_University/Pictures/pdo_eof1"
  wks1                                    = gsn_open_wks("png", wksname1)
  wksname2                            = "/cygdrive/E/Fudan_University/Pictures/pdo_pc1"
  wks2                                    = gsn_open_wks("png", wksname2)
; ;
; This will not be necessary in V6.1.0 and later. Named colors can
; be used without having to first add them to the color map.


                                          ; only needed if paneling
  res                                = True
  res@gsnDraw                 = False
  res@gsnFrame                = False
  res@gsnSpreadColors      = True         ; spread out color table
  res@gsnSpreadColorEnd   = -2           ; don't use added gray
  res@gsnAddCyclic            = False        ; data not cyclic


  res@mpCenterLonF        = 190.         ; defailt is 0 [GM]
  res@mpMinLatF            = min(x&lat)
  res@mpMaxLatF            = max(x&lat)
  res@mpMinLonF            = min(x&lon)
  res@mpMaxLonF            = max(x&lon)
  res@mpFillDrawOrder      = "PostDraw"

  res@cnFillOn                = True         ; turn on color fill
  res@cnLinesOn             = True         ; True is default
  res@lbLabelBarOn         = True        ; turn off individual lb's
                                          ; set symmetric plot min/max


  res@gsnLeftString     = "EOF "+1
  res@gsnRightString   = sprintf("%5.1f",eof@pcvar(0)) +"%"
  plot1                        = gsn_csm_contour_map_ce(wks1,eof_regres(0,:,:),res)

;*******************************************
; time series (principal component) plot
;*******************************************

rts                                   = True
rts@gsnDraw                    = False
rts@gsnFrame                   = False

; these four resources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.
  rts@vpHeightF                 = 0.40        ; Changes the aspect ratio
  rts@vpWidthF                  = 0.85
  rts@vpXF                      = 0.10        ; change start locations
  rts@vpYF                      = 0.75        ; the plot

rts@gsnXYBarChart              = True
rts@gsnYRefLine                  = 0.0
rts@gsnAboveYRefLineColor      = "Red"
rts@gsnBelowYRefLineColor      = "Blue"

  year = cd_calendar(eof_ts&time,1)

  tt = fspan(1,1428,1428)
  rts@gsnLeftString   = "EOF "+1
  rts@gsnRightString  = sprintf("%5.1f",eof@pcvar(0)) +"%"
  plot2               = gsn_csm_xy (wks2,year,eof_ts(0,:),rts)


draw(plot1)
draw(plot2)
frame(wks1)
frame(wks2)

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

使用道具 举报

 楼主| 发表于 2019-12-7 22:31:24 | 显示全部楼层
设置rts@xyLineColor                = "transparent"  就可以解决了(虽然不知道为啥之前画图都没遇到这个问题)
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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