[ncl-talk] Problem with gsn_add_polymarker

Jesús Garcia Rosales jesus21gr at gmail.com
Thu Nov 5 14:02:14 MST 2015


Hi ncl users,
I have a problem to display my stations' position with differents colors,
using gsn_add_polymarker. When I use:

 mkres at gsMarkerColor = colors
dum3 = gsn_add_polymarker(wks,plot,lon,lat,mkres)

It works, but only displays the stations with one color.
My script is the next:

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/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

begin
;---Open WRF output file.
  dir      = "/media/usuario/TOSHIBA/WRF_alan/9km/"
  filename = "wrfout_d01_2010F.nc"
  a = addfile(dir + filename,"r")

;---Read terrain height and lat/lon off file.
  it        = 0     ; first time step
  hgt       = wrf_user_getvar(a,"HGT",it)    ; Terrain elevation
  hgt at lat2d = wrf_user_getvar(a,"XLAT",it)   ; latitude/longitude
  hgt at lon2d = wrf_user_getvar(a,"XLONG",it)  ; required for plotting

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Grafico
;;;;;;;;;;;;; Salida
 type = "x11"
 ;type = "pdf"
 ;type = "ps"
; type = "ncgm"


  wks = gsn_open_wks(type,"graficas/topografia_cuenca")

;---Set some basic plot options
  res               = True

  res at gsnMaximize   = True   ; maximize plot in frame
  res at gsnDraw       = False
  res at gsnFrame      = False

  res at tiMainString  = filename

  res at cnFillOn      = True
  res at cnFillPalette = "OceanLakeLandSnow"
  res at cnLinesOn     = False

  res at mpProjection  = "CylindricalEquidistant"    ; The default

;---Zoom in on plot
  res at mpMinLatF     = -13.8
  res at mpMaxLatF     = -10.5
  res at mpMinLonF     = -77
  res at mpMaxLonF     = -73.6

;---Additional resources desired
  res at pmTickMarkDisplayMode = "Always"   ; nicer tickmarks

  res at mpDataBaseVersion     = "MediumRes"       ; better and more map
outlines
  res at mpDataSetName         = "Earth..4"
  res at mpOutlineBoundarySets = "AllBoundaries"
  res at mpOutlineOn           = True

  res at lbOrientation         = "Vertical"
  res at tiMainOffsetYF        = -0.03           ; Move the title down

;---Change contour levels to better match the color map being used
  res at cnLevelSelectionMode = "ExplicitLevels"
  res at cnLevels = (/2,100,200,400,600,800,1000,1200,1400,1600,1800,2000,\

2200,2400,2800,3000,3200,3400,3600,3800,4000,4200,4400,4600,4800,5000,\
                  5200,5400/)


  res at gsnAddCyclic = False

 plot = gsn_csm_contour_map(wks,hgt,res)

 cuenca_mantaro_shp_name = "/home/usuario/Escritorio/alan/cuencas/UH.shp"

  lnres                  = True
  lnres at gsLineColor      = "black"
  lnres at gsLineThicknessF = 4

 can_id =
gsn_add_shapefile_polylines(wks,plot,cuenca_mantaro_shp_name,lnres)

  ; Coordenadas de cada estación que se quiere ubicar

  lat=(/-12.04, -10.69, -11.4, -11.33, -12.25, -12.12, -11.4, -11.75,
-11.88, -11.62, \
        -11.78, -12, -12.16, -12.38, -12.35, -12.58, -12.78, -12.98,
-13.06, -12.84/)

  lon=(/-75.32, -76.26, -76.33, -76.4, -75.36, -75.43, -75.69, -75.13,
-75.27, -75.01,\
        -75.47, -75.22, -75.23, -74.85, -75.08, -75.24, -75.01, -74.72,
-74.14, -74.57/)



 colors =
(/"orange2","forestgreen","dodgerblue2","forestgreen","orange2","orange2","forestgreen","dodgerblue2",\

 "dodgerblue2","olivedrab2","forestgreen","orange2","orange2","olivedrab2","darkorchid2","olivedrab2",\
           "forestgreen","darkorchid2","olivedrab2","darkorchid2"/)


  labels = (/"Huayao","Cerro de
Pasco","Marcapomacocha","Yantac","Laive","Jarpa","Tarma","Comas"\
           ,"Ingenio","Ricran","Jauja","Santa
Ana","Viques","Pampas","Pilchaca","Huancalpi"\
            ,"Huancavelica","Lircay","Quinua","Acobamba"/)

; Manually specify location of legends

  xleg =
(/0.15,0.15,0.15,0.15,0.15,0.35,0.35,0.35,0.35,0.35,0.56,0.56,0.56,0.56,0.56,0.80,0.80,0.80,0.80,0.80/);
Location of
  xtxt =
(/0.22,0.225,0.225,0.225,0.225,0.44,0.44,0.44,0.44,0.44,0.65,0.66,0.66,0.66,0.66,0.88,0.88,0.88,0.88,0.88/)
 ; legend markers
  yleg =
(/0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08/)
  ; and text
  ytxt =
(/0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08,0.20,0.17,0.14,0.11,0.08/)
 ; strings.

  mkres               = True
  mkres at gsMarkerIndex = 17     ; Filled circle
  mkres at gsMarkerSizeF = 0.05    ;0.03

  txres               = True
  txres at txFontHeightF = 0.014


 do i = 0,19

    mkres at gsMarkerColor = colors(i)
    dum3(i)=  gsn_add_polymarker(wks,plot,lon(i),lat(i),mkres)
    ; gsn_polymarker_ndc(wks,xleg(i),yleg(i),mkres)
    ; gsn_text_ndc      (wks,labels(i),xtxt(i),ytxt(i),txres)


  end do

 ;mkres at gsMarkerColor = colors

; dum3 = gsn_add_polymarker(wks,plot,lon,lat,mkres)


 draw(plot)
 frame(wks)


  end


Thanks for your time,

Jesus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151105/6af4a8ef/attachment.html 


More information about the ncl-talk mailing list