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 npts=56 apr =asciiread("INapr_point2.txt",(/npts/),"float") mnmxint = nice_mnmxintvl(min(apr),max(apr),10,True) nlevels = toint(((mnmxint(1)-mnmxint(0))/mnmxint(2))) + 1 levels = fspan(mnmxint(0),mnmxint(1),nlevels) print("min/max data = " + min(apr) + "/" + max(apr)) print("# of groups = " + (nlevels-1)) print("levels start at = " + levels(0) + ", end at " + levels(nlevels-1) + \ ", with a spacing of " + mnmxint(2)) ;---Create new 2D array to hold groupings of values data2d = new((/nlevels-1,npts/),typeof(apr)) printVarSummary(data2d) printVarSummary(apr) ;---Group the values and put in 2D array. labels = new(nlevels-1,string) do i=0,nlevels-2 ii = ind(apr.ge.levels(i).and.apr.lt.levels(i+1)) data2d(i,ii) = apr(ii) labels(i) = levels(i) + ":" + levels(i+1) delete(ii) end do ;================================================= ;---Define the colors for the markers. white/black = background/foreground colors = (/"white","black","darkgoldenrod","darkgreen","coral4", \ "cyan3","firebrick1","darkslateblue","limegreen", \ "lightgoldenrod","darkseagreen1","lightsteelblue1"/) wks = gsn_open_wks("X11","scatter_color") ; specifies a ps plot gsn_define_colormap(wks,colors) ;---Create a scatter plot res = True ; plot mods desired res@gsnMaximize = True res@tiMainString = "Scatter plot with grouped markers" ;---Set some legend resurces res@pmLegendDisplayMode = "Always" ; Turn on the legend res@lgOrientation = "horizontal" ; Default is vertical res@pmLegendWidthF = 0.75 ; Make it wider res@pmLegendOrthogonalPosF = -0.1 ; Move it up slightly res@lgPerimOn = False ; Turn off the perimeter box res@xyExplicitLabels = labels ; Set the legend labels ;---Set some marker resources res@xyMarkLineMode = "Markers" res@xyMarkerThicknessF = 2.5 res@xyMarkerColors = colors(2:) ; It's okay to list more than you need here res@xyMarkers = ispan(2,16,1) ; Again, you can list more than you need. plot = gsn_csm_y (wks,data2d,res) end