[ncl-talk] Scatter plot

Ipsita Putatunda ipsita.putatunda at gmail.com
Wed Sep 10 02:15:09 MDT 2014


Hi all,
   I have a 2D variable (nlev*ntim) with values ranges approx from 0 to 20.
I want to make a scatter plot with xaxis labeling ntim and yaxis with nlev,
and the values am grouping in 10 sets (0-2,2-4,4-6,6-8,8-10,10-12...etc)
and trying to put it in different colors. While doing so am getting problem
related to array subscription. The way am making the subsets of the values
may be wrong.

My script is attached herewith.
it is giving error

fatal:Number of dimensions in parameter (0) of (ind) is (2), (1) dimensions
were expected
fatal:["Execute.c":7743]:Execute: Error occurred at or near line 56 in file

At line 56
  ii = ind(levels(i).le.data1.and.data1.lt.levels(i+1))
as the data1 is 2D I have to write it some other way for making the subset.
I have tried to follow the examples
http://www.ncl.ucar.edu/Applications/Scripts/scatter_6.ncl
http://www.ncl.ucar.edu/Applications/Scripts/scatter_8.ncl
but getting similar issue.
I know where am making mistake,but don't know how to solve it. If anyone
could help me out this issue will be appreciated.

Thanks,
Ipsita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140910/e6085884/attachment.html 
-------------- next part --------------
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"

; ==============================================================
; User defined parameters
; ==============================================================
  begin
  jan1 =asciiread("INjan_point2.txt",(/56,2/),"float")
  jan=jan1(:,1)
  feb =asciiread("INfeb_point2.txt",(/56/),"float")
  mar =asciiread("INmar_point2.txt",(/56/),"float")
  apr =asciiread("INapr_point2.txt",(/56/),"float")
  may =asciiread("INmay_point2.txt",(/56/),"float")
  jun =asciiread("INjun_point2.txt",(/56/),"float")
  jul =asciiread("INjul_point2.txt",(/56/),"float")
  aug =asciiread("INaug_point2.txt",(/56/),"float")
  sep =asciiread("INsep_point2.txt",(/56/),"float")
  oct =asciiread("INoct_point2.txt",(/56/),"float")
  nov =asciiread("INnov_point2.txt",(/56/),"float")
  dec =asciiread("INdec_point2.txt",(/56/),"float")
  data= (/jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec/)
  data!0="month"
  data!1="height"
  data1=data(height|:,month|:)
; print(data)
; print(jan)
;=================================================
;---Generate some levels to group the data values by.
  levels  = ispan(1,20,2)
  nlevels = dimsizes(levels)
  print(nlevels)
  print(levels)

;---For each range, we want a different color.
  colors = (/"limegreen","orange","green","red","yellow","purple","blue",\
             "red","brown","red2","skyblue"/)

;---Start the graphics
  wks = gsn_open_wks("X11","scatter")

  res              = True
  res at gsnMaximize  = True                 ; Maximize plot in frame

  res at gsnDraw      = False                ; Don't draw plot
  res at gsnFrame     = False                ; Don't advance frame (page)
  xy = gsn_csm_y(wks,data1,res)
  mkres = True

  dum_fill   = new(nlevels-1,graphic)
  mkres at gsMarkerThicknessF = 2.0      ; Twice as thick
;
; For each range, gather the data that falls in this range
; and draw the set of markers at those x/y locations.
;
  do i=0,nlevels-2
    ii = ind(levels(i).le.data1.and.data1.lt.levels(i+1))
    mkres at gsMarkerIndex = 16          ; Filled dots
    mkres at gsMarkerColor = colors(i)
    dum_fill(i) = gsn_add_polymarker(wks,xy,height(ii),month(ii),mkres)
    delete(ii)
  end do

;---Drawing the map plot will draw all the attached markers too.
  draw(xy)
  frame(wks)
end


More information about the ncl-talk mailing list