How do you make levels spanning a range?
Say we have data that runs from a minimum value of -3.4 to a
maximum value of 5.6. If we want a list of
even levels whose endpoints are identical
to the enpoints of this range, we use the
mkevenlevels
command:
>>> import vcs >>> levels = vcs.mkevenlevels(-3.4, 5.6) >>> ['%.4g' % levels[i] for i in range(len(levels))] ['-3.4', '-2.5', '-1.6', '-0.7', '0.2', '1.1', '2', '2.9', '3.8', '4.7', '5.6']
This produces exactly 11 levels values (i.e. 10 level intervals), unless you specify a smaller number of intervals:
>>> levels = vcs.mkevenlevels(-3.4, 5.6, 4)
>>> ['%.4g' % levels[i] for i in range(len(levels))]
['-3.4', '-1.15', '1.1', '3.35', '5.6']
To make a list of levels that are "nice" (i.e. at natural
breakpoints), but that also span the range, use
mkscale
:
>>> levels = vcs.mkscale(-3.4, 5.6)
>>> levels
[-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
The zero
keyword
also allows you to set whether you want 0 to be a level:
Keyword Zero
ValueDescription -1 Zero is forced to not be a level 1 Zero is permitted to be a level (default) 2 Zero forced to be a level
For instance:
>>> print vcs.mkscale(-3.4, 5.6, 5, zero=-1)
[-5.0, -3.0, -1.0, 1.0, 3.0, 5.0, 7.0]
>>> print vcs.mkscale(-3.4, 5.6, 5, zero=1)
[-4.0, -2.0, 0.0, 2.0, 4.0, 6.0]
>>> print vcs.mkscale(-3.4, 5.6, 5, zero=2)
[-4.0, -2.0, 0.0, 2.0, 4.0, 6.0]
Note you can set the maximum number of intervals
in mkscale
as the third positional argument.
It isn't always enforced, however (as seen in the first
zero=-1
example above).
The Python help
command
(e.g. help(vcs.mkscale)
) gives some more information.
Descriptions of these VCS function are also found in the
Quick Start
document.
Notes: This discussion applies to CDAT 3.3.