[ncl-talk] color bar

Mary Haley haley at ucar.edu
Wed Jan 4 07:19:11 MST 2017


Hi Laura,

NCL doesn't base the color bar levels on the type of the data. What it does
is look at the min/max of your data, and then tries to pick a set of levels
such that you get an equally-spaced span of 10-16 levels. This can very
likely result in a set of levels that require floating point values.

So, for example, if the min of your difference is 0, and the max is 1, NCL
is going to pick levels (/0,0.1,0.2,...,0.9,1/). If the min/max is 0 and 2,
then NCL will choose (/0.0, 0.2, 0.4, ..., 1.8, 2.0/)

Here's a little program that illustrates the various values that NCL will
pick for levels, using the nice_mnmxintvl function:

procedure print_levels(ymin,ymax)
local x
begin
  print("data min, max = " + ymin + ", " + ymax)
  x = nice_mnmxintvl(ymin,ymax,16,False)
  print("   levels min     = " + x(0))
  print("   levels max     = " + x(1))
  print("   levels spacing = " + x(2))
end

;---Print level min/max/spacing for various min/max values for data.
print_levels(  0,  1)
print_levels(  0,  2)
print_levels(  0,  5)
print_levels(  0, 10)
print_levels(-10, 10)
print_levels(0.1, 0.9)

This results in:

data min, max = 0, 1
   levels min     = 0
   levels max     = 1
   levels spacing = 0.1
data min, max = 0, 2
   levels min     = 0
   levels max     = 2
   levels spacing = 0.2
data min, max = 0, 5
   levels min     = 0
   levels max     = 4.8
   levels spacing = 0.4
data min, max = 0, 10
   levels min     = 0
   levels max     = 10
   levels spacing = 1
data min, max = -10, 10
   levels min     = -10
   levels max     = 10
   levels spacing = 2
data min, max = 0.1, 0.9
   levels min     = 0.15
   levels max     = 0.85
   levels spacing = 0.05

You can set the levels to whatever values you want.  For example, the
following will create levels starting at the minimum of your difference,
and going to the maximum of your difference, in steps of 1:

res at cnLevelSelectionMode = "ExplicitLevels"
res at cnLevels             = ispan(toint(min(diff)),toint(max(diff)),1)

--Mary



On Tue, Jan 3, 2017 at 9:43 AM, Laura Fowler <laura at ucar.edu> wrote:

> Hello:
>
> I am plotting a global map of the difference between two fields that
> are both integers. A printVarSummary inquiry also shows that the
> difference filed is also an integer. so, I am not iunderstanding why
> the color bar labels are actually real with decimals. Does this make
> sense? I would think that the color bar labels would also be integers?
>
> Thanks,
> Laura
>
>
> --
> !-----------------------------------------------------------
> --------------------------------------------------
> Laura D. Fowler
> Mesoscale and Microscale Meteorology Division (MMM)
> National Center for Atmospheric Research
> P.O. Box 3000, Boulder CO 80307-3000
>
> e-mail: laura at ucar.edu
> phone: 303-497-1628
>
> !-----------------------------------------------------------
> --------------------------------------------------
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170104/ca03e48a/attachment.html 


More information about the ncl-talk mailing list