[ncl-talk] reply: draw a dot-line in a xy_plot and pots with differentcolor on the plot according to the data value

grace 313695096 at qq.com
Mon Jan 2 18:03:42 MST 2017


Hi:
    All,I am trying to  draw a dot-line in a xy_plot that emphasize different parts of it with different colors according to its values.
   I have write a scirpt according to the example,but the dots have  same color.According to Rick's advise,I've changed the "dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,:),data(1,:),mkres) "
to "dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,ii),data(1,ii),mkres)",but error occurred:
 
fatal:Subscript out of range, error in subscript #1
fatal:An error occurred reading data
fatal:["Execute.c":8567]:Execute: Error occurred at or near line 84 in file xypot_aqi.ncl
  
 I don't know why and can't find where the problem is.

  
 This is my script:
 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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
 begin
  ;---Read in file as array of strings so we can parse each line.
      ; filename= "/public/home/huanglei/bias_T_5km.txt"
      ; lines  := asciiread(filename,-1,"float")
      ; nlines = dimsizes(lines)-1   ; First line is a header
       
        data=new((/2,7/),float)
       ;  data(1,:)=lines(:,1)   ;;get the aqi_data
        data(1,:)=(/10,25,56,90,230,450,490/)
;;;;;;;;;;;;;;;;;;;make X axis;;;;;;;;;;;;;;;;;;;;;; 
  ;d1=new(1272,float)
 ;d1(0)=1
 ;do s=1,1271
  ;   d1(s)=d1(s-1)+1
 ;end do
     data(0,:) = (/1,2,3,4,5,6,7/)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
; We generate plots, but what kind do we prefer?;;;;make a fake plot to attach the pots ,line is white;;;
  type = "pdf"
  wks = gsn_open_wks(type,"xypot_aqi")
  
  res1=True
   res1 at gsnFrame  = False
  res1 at gsnDraw  = False   
  res1 at xyLineThicknesses = 0.1               ; make 2nd lines thicker
  res1 at xyLineColors      = "white"         ; change line color
 res1 at pmLegendDisplayMode    = "always"              ; turn on legend
 res1 at pmLegendSide           = "Top"                ; Change location of 
 res1 at pmLegendParallelPosF   = .89                 ; move units right
 res1 at pmLegendOrthogonalPosF = -1.17                  ; more neg = down
 res1 at lgPerimOn              = False      ; No legend perimeter.
   res1 at trXMinF                =1
   res1 at trXMaxF                =7
    res1 at tmXBMode ="Explicit"  
    res1 at tmXBValues  =(/1,2,3,4,5,6,7/)
    res1 at tmXBLabels = (/"8/1"," 8/11"," 8/21"," 9/1","9/11", \
                   " 9/21","9/20"/)
  res1 at vpHeightF   = 0.35
  res1 at vpWidthF    = 0.75
  ;res1 at tiYAxisString  = "mm"      ; add an axis title   
   res1 at gsnLeftString        ="AQI of Xian"
  res1 at pmLegendWidthF         = 0.10                  ; Change width and
  res1 at pmLegendHeightF        = 0.10                  ; height of legend.
  res1 at lgLabelFontHeightF     = 0.02                   ; change font height
  plot= gsn_csm_xy(wks,d1,data(1,:),res1)
 ;;;;;;attach the different color pots according to the data value;;;
 ;---Generate some levels to group the data values by.
  levels    = ispan(0,500,50)
  nlevels   = dimsizes(levels)
   ;;;;;;;;;;;---For each range, we want a different  color.
  colors = (/"yellow","green","orange","red","violet","violet","violetred4","violetred4","violetred4","violetred4"/)
;;;;Arrays for attaching markers;;;
    dot_fill_trn = new(nlevels-1,graphic)
; For each range, gather the data that falls in this range
; and draw the set of markers at those x/y locations.
;
  mkres = True
  do i=0,nlevels-2
  ;  print(i)
    ii = ind(levels(i).le.data(1,:).and.data(1,:).lt.levels(i+1))
    
    mkres at gsMarkerIndex    = 16          ; Filled dots
    mkres at gsMarkerSizeF    = 5
    mkres at gsMarkerColor    = colors(i)
    print(colors(i))
;---Make markers partly transparent (1.0 is fully opaque)
    mkres at gsMarkerOpacityF = 0.9
    dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,ii),data(1,ii),mkres)
     delete(ii)
  end do
 ;---Drawing the map plots will draw all the attached markers too.
  draw(plot)
  frame(wks)
end

 Can you slove this problem?Any information will be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170103/a582369c/attachment.html 


More information about the ncl-talk mailing list