Re: color bar question

From: Mary Haley (haley AT XXXXXX)
Date: Thu Aug 15 2002 - 17:44:13 MDT

  • Next message: Sylvia Murphy: "color bar question"

    >
    > Hi, this may have come up already, but we're having trouble, short of
    > hard coding the values, how does one set the color bar numbers to
    > scientific and or say xx.xx (2 decimal places)? We've figured out
    > how to int them and are dynamically assigning values. but we can't
    > figure out how to limit the decimal places or how to do scientific:
    > res .CnMaxDataValueFormat = ".1f" does nothing. thanks, pb
    > --
    >

    You might try using "lbLabelStrings" and formatting it as desired
    using "sprintf". You will need to get the latest gsn_code.ncl and
    gsn_csm.ncl (I modified them today) in order for this to work:

       http://ngwww.ucar.edu/ngdoc/ng/ug/ncl/gsun/scripts/gsn_code.ncl
       http://ngwww.ucar.edu/ngdoc/ng/ug/ncl/gsun/scripts/gsn_csm.ncl

    Sprintf works much like the C version of "sprintf". That is, if you
    want 2 values plotted after the decimal place, and you have a total of
    5 characters that you want in your numbers (you must include a count
    for the decimal place), then you use "5.2f". Below is an example.
    For more information on sprintf, go to:

       http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/functions/sprintf.html

    Note: in the example below, I'm assuming you don't know your contour
    levels beforehand, so I'm retrieving them with the "cnLevels" resource
    and then recreating the plot with "lbLabelStrings" set.

    --Mary

    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

    begin
      wks = gsn_open_wks("x11","test")

      file1 = addfile(ncargpath("data") + "/cdf/cn10n.cdf","r")

      cnres = True
      cnres@cnFillOn = True
      cnres@lbLabelFontHeightF = 0.015
      cnres@cnLevelSelectionMode = "ManualLevels"
      cnres@cnMinLevelValF = 4.15
      cnres@cnMaxLevelValF = 44.15
      cnres@cnLevelSpacingF = 4

      contour = gsn_csm_contour(wks,file1->mound,cnres)
    ;
    ; Retrieve contour levels.
    ;
      getvalues contour
        "cnLevels" : levels
      end getvalues

      cnres@lbLabelStrings = sprintf("%4.1f",levels) ; Format the labels
      contour = gsn_csm_contour(wks,file1->mound,cnres)

    end
    _______________________________________________
    ncl-talk mailing list
    ncl-talk AT ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Thu Aug 15 2002 - 20:53:00 MDT