Hi Santheesan,
I modified your code and fixed the problems you were having. Two
issues were fairly easy to spot, the third was more subtle:
a) you need to use a number of contour levels that is equal or smaller
than the number of colors in your color mapa defined colormap
b) you need to set the colormap to one that exists (either one of the
predefined ones, or one that you create). Your code was trying to create
one from an rgb file that didn't exist (another element of that 2nd
trajectory example).
c) you need to draw the map BEFORE the polystuff is added - if you call
it afterward, it overwrites the polyline
Please see the comments in the attached code for more explanation.
Best regards,
Jonathan
Satheesan wrote:
> Hi Jonathan,
>
> Thank you for your suggestion. I made some changes to the traj_2.ncl
> and still I am unable to get the colours. It complains that " Not
> enough colors in colormap for number of contour levels" and plotting a
> black line. Also it is plotting under the map. What could be the problem.
>
> Thanks & Regards,
>
> Satheesan
>
> On Tue, Apr 15, 2008 at 6:53 PM, Jonathan Vigh
> <vigh_at_atmos.colostate.edu <mailto:vigh_at_atmos.colostate.edu>> wrote:
>
> Hi Santheesan,
> Take a look at the code for example 2 on the trajectory examples
> page (traj_2.ncl). The trick is to draw the trajectory one sement
> at a time while using the GetFillColor function to assign the
> appropriate color based on your scalar value.
>
> http://www.ncl.ucar.edu/Applications/traj.shtml
>
> Regards,
> Jonathan
>
>
>
>
> Satheesan wrote:
>
> Dear NCL users,
>
> I am trying to plot a trajectory over the south pole, where
> the data is in the format
> lon, lat, parameter (untraj.dat)
> I have to plot this trajectory with the parameter in different
> colors as its value changes (like a contour along the trajectory).
> I am able to draw the trajectory, but not able to do it with
> different colors. How do I make it with different colors (i.e
> I have to change the Red colored line into a line with
> different colors as the parameter varies and a colorbar). I
> have attached the files.
> Can you help me?
>
> Thanks & Regards
>
> Satheesan
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu <mailto:ncl-talk_at_ucar.edu>
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
;*************************************************
; traj_2.ncl
;*************************************************
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"
;**************************************************
begin
;*************************************
; read in data
;************************************
; note this trajectory file contains data in the form of
; 9 variables x 131 timesteps x 100 trajectories
tStr = readAsciiTable("untraj.dat",3,"float",0)
ntime = dimsizes(tStr)
;********************************************
wks = gsn_open_wks("X11","traj") ; open workstation
;*********************************************
; color preps
;*********************************************
; You had:
; cnLevels=fspan(200.0,3400.0,300)
; Change this to:
cnLevels=fspan(200.0,3400.0,9) ; JV: you had 300 here - I doubt that you really wanted 300 different colors - you need cnLevels to be smaller than the number of colors in the color table you want to use or you'll run out of colors
print(cnLevels) ; JV: this shows that using 9 values gives nice evenly spaced intervals
; You had:
; cmap = RGBtoCmap ("redyellowblue.rgb") ; JV: this was relevant to that particular example which was also showing how to convert an rgb file to a colormap
; gsn_define_colormap (wks,cmap)
; Change it to:
gsn_define_colormap (wks,"cosam12") ; JV: set this to one of the named color maps. There are a # of nice predefined color tables - see http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml
cmap = gsn_retrieve_colormap (wks) ; JV: now retrieve the colors in your chosen colormap using gsn_retrieve_colormap - for more, see http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_retrieve_colormap.shtml
print(cmap) ; JV: for kicks, print the colormap and you'll see it's a 2D array with the first dimension being the color, and the second being triplets
res = True ; map resources
res_at_gsnDraw = False ; don't draw
res_at_gsnFrame = False ; don't advance frame
res_at_gsnPolar = "SH"
res_at_mpMaxLatF = -60 ; select subregion
res_at_mpMinLatF = -90
res_at_mpGridSpacingF = 10.0
; label bar resources
res_lb = True
res_lb_at_vpWidthF = 0.60
res_lb_at_vpHeightF = 0.10
res_lb_at_lbPerimOn = True ; Turn off perimeter.
res_lb_at_lbOrientation = "Horizontal" ; Default is vertical.
res_lb_at_lbLabelStride = 2
res_lb_at_lbLabelAlignment = "InteriorEdges" ; Default is "BoxCenters".
res_lb_at_lbFillColors = cmap(2:,:) ; Colors for boxes.
res_lb_at_lbMonoFillPattern = True ; Fill them all solid.
res_lb_at_lbLabelFontHeightF = 0.015
res_at_tiMainString = "Trajectories colored by salinity (ppt)" ; title
map = gsn_csm_map_polar(wks,res) ; create map
; You need to draw the map here rather than later, so add this next line.
draw(map) ; JV - see comment below - by drawing the map at this point, we will put the polyline stuff over top of it
pres = True
pres_at_gsLineThicknessF = 8.0
mres = True
first = True
xpt = tStr(:,0)
ypt = tStr(:,1)
sst = tStr(:,2)
;dum = new(ntime,graphic)
do j=0,dimsizes(ypt)-2
pres_at_gsLineColor =GetFillColor(cnLevels,cmap(2:,:),avg( (/sst(j),sst(j+1)/)))
; dum=gsn_add_polyline(wks,map,(/xpt(j),xpt(j+1)/),(/ypt(j),ypt(j+1)/),pres)
gsn_polyline(wks,map,(/xpt(j),xpt(j+1)/),(/ypt(j),ypt(j+1)/),pres)
end do
; You had:
; draw(map) ; you were drawing the map after the polyline stuff, overwriting it - instead call it before the polyline stuff is done
frame(wks)
end
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 15 2008 - 15:18:33 MDT
This archive was generated by hypermail 2.2.0 : Wed Apr 16 2008 - 11:00:26 MDT