2010/3/14 David Arnold <dwarnold45@...2108...>:
All,
I am having difficulty with a line on: http://scipy.org/LoktaVolterraTutorial
Here are the lines:
values = linspace(0.3, 0.9, 5)
vcolors = p.cm.autumn_r(linspace(0.3, 1., len(values)))
First of all, I can find no reference to autumn_r in the Matplotlib documentation. Also, using Aptana (eclipse), PyDev complains about the vcolors line with:
The colormap's data is defined in matplotlib._cm.py, there a
dictionary defining the names of the colormaps is defined from line
no. 5814 on. The colormaps are "imported", i.e. added to the
module-local namespace by "patching" locals() in matplolib.cm on line
43, where cmap_d also containes reversed versions of all the data
defined by matplotlib._cm, indicated by an trailing "_r" in the name.
Because the data isn't imported the usual way, your program (PyDev?)
will not find it.
Undefined variable from import: autumn_r Lotka.py /scipy/src/pkg line 44 PyDev Problem
Secondly, I am used to using colormaps in Matlab, but not so much in Matplotlib. In Matlab, g=grey(256) produces an 256x3 matrix and each row is indexed by the numbers 1 through 256. Thus, if you have an image and pixel has a value 124, then row 124 gives an rgb triple that is used to color the pixel.
I think you can reproduce the matlab behaviour by using:
result = some_colormap(numpy.linspace(0.0, 1.0, 256), [bytes = True]).
The optional bytes = True argument specifies to return integer \in [0,
255] colors. The return ndarray will have shape (256, 4), and an
indicing result[i] returns the ndarray array([r, g, b, a]). Note than
numpy and Python use zero-based indices, opposed to matlab's one-based
indices.
However, in the case of vcolors = p.cm.autumn_r(linspace(0.3, 1., len(values))), I'm really not sure what is going on. The linspace(0.3,1,len(values)) produces len(values) equally spaced numbers from 0.3 to 1. Now, how is autumn_r(array([ 0.3 , 0.475, 0.65 , 0.825, 1. ])) make any sense?
The first argument to some_colormap.__call__(X, alpha [= 1.0], bytes
[= False]) is the interpolation axis. I embed __call__()'s __doc__
string:
"""
*X* is either a scalar or an array (of any dimension).
If scalar, a tuple of rgba values is returned, otherwise
an array with the new shape = oldshape+(4,). If the X-values
are integers, then they are used as indices into the array.
If they are floating point, then they must be in the
interval (0.0, 1.0).
Alpha must be a scalar.
If bytes is False, the rgba values will be floats on a
0-1 scale; if True, they will be uint8, 0-255.
"""
I myself just did a short dive into the matplotlib code of cm.py,
_cm.py, and colors.py, so this are just my conclusions.
Friedrich