[Newbie] question concerning color mapping

Dear list,

I recently came across the following code:

In [7]: size = 50*np.random.randn(100)
In [8]: colours = np.random.rand(100)
In [9]: scatter(x, y, s=size, c=colours);
In [10]: show()

which works beautifully. My question though is this: why?

I came to understand, with Google's help, that the randomly generated
values (ranging between 0.0 and 1.0) for the variable colours are mapped
to a color table, so that the generated value of, say, 0.21985792 is
linked to a given color. This color is then used to paint one scatter point.

I was unable to find helpful (i.e. newbie friendly) information on how
this color mapping exactly works. Where is the table? The matplotlib
documentation caused me confusion.

Thanks for your kind help,

David

Hello,

the np.random.randn() functions returns a list (or an array if given appropriate arguments) of normal distributed numbers.

If x and y are also of length 100, each couple (x[i],y[i]) will be assigned a size size[i] and a color colours[i].

This happens not at all because of magic, but because the 's' and 'c' keyword arguments to scatter accept an array of number as the setting to give to each individual point.

The routine scatter automatically finds the maximun and minimum in "colours" and give to each point a color value according to the default colormap.

Details can be found in the docs:
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.scatter

I could not find any newbie specific information on "scatter".
If you need help regarding a function, it is available at the command line.

>>> help(scatter)

Pierre

···

Le 26 nov. 09 à 11:06, David a écrit :

Dear list,

I recently came across the following code:

In [7]: size = 50*np.random.randn(100)
In [8]: colours = np.random.rand(100)
In [9]: scatter(x, y, s=size, c=colours);
In [10]: show()

which works beautifully. My question though is this: why?

I came to understand, with Google's help, that the randomly generated
values (ranging between 0.0 and 1.0) for the variable colours are mapped
to a color table, so that the generated value of, say, 0.21985792 is
linked to a given color. This color is then used to paint one scatter point.

I was unable to find helpful (i.e. newbie friendly) information on how
this color mapping exactly works. Where is the table? The matplotlib
documentation caused me confusion.

Thanks for your kind help,

David

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users