[ncl-talk] text res

Mary Haley haley at ucar.edu
Mon Oct 19 13:02:02 MDT 2015


Geeta,

Please email all follow-up questions to ncl-talk at ucar.edu, and do not send
them to me directly.

You need to group the text strings by the color you want to render them
in.  So, you should be looping across the number of ranges you have, and
not each value. Your code would look something like this:

  range_bot = (/   0.1,   2.5,      7.5/)
  range_top = (/   2.5,   7.5,     15.5/)
  colors    = (/"Blue", "Red", "Green"/)
  nranges   = dimsizes(range_bot)
;
; Loop through each range and get the indices of

; all the values that fall in this range. These

; are the values that should be drawn in the given
          ; ; color.
;

  do n=0,nranges-1
    ii := ind(rf.ge.range_bot(n).and.rf.lt.range_top(n))
    if(.not.any(ismissing(ii))) then
      txres at txFontColor = colors(n)     ; set the color for this range
      unqstr = unique_string("text")    ; generate a unique id for text
object
      plot@$unqstr$ = gsn_add_text(wks,plot," "+sprintf("%9.4g",rf(ii)), \
                                       lon(ii),lat(ii),txres)
    end if
  end do


See the attached script, which is based on your script, but using random
data.

--Mary


On Mon, Oct 19, 2015 at 11:02 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:

>  Hi Mary.
> I have tried three things for giving a range to the rainfall. Pls see the
> lines 91 to 110 of my script.
>
>
>
> 1.  I tried the following.
>
> 1. print(nrf)
>      92   colors = where(((rf.ge.0.1).and.(rf.lt.2.5)),"Blue","   ")  ;
> This is a string variable
>      93   colors = where(((rf.ge.2.5).and.(rf.lt.7.5)),"Red","   ")
>      94 ;  colors = where(((rf.ge.7.5).and.(rf.lt.15.5)),"Yellow","   ")
>      95 ;  colorss= stringtoint(colors)
>
> 2nd Method in which I have defined the colors as an array. So there is
> error on line 106. Also this will give an individual color to each data.
> Variable: colors
> Type: integer
> Total Size: 16 bytes
>             4 values
> Number of Dimensions: 1
> Dimensions and sizes:    [4]
> Coordinates:
> (0)    1
> (1)    21
> (2)    41
> (3)    61
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading colors
> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 106 in
> file stn-v3.ncl
>
> aditya at agniilap:~/geeta/ncl$
>
> can U pls suggest???I also tried combining two statements with where but
> that did not work.
>  Geeta.
>
> Geeta.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151019/16e453d2/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: text_colors.ncl
Type: application/octet-stream
Size: 2838 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151019/16e453d2/attachment.obj 


More information about the ncl-talk mailing list