Question: I am new to python and am having trouble finding the correct syntax to use.
I want to plot some supernovae data onto a hammer projection. The data has coordinates alpha and beta. For each data point there is also a value delta describing a property of the SN. 
I would like to create a colour scale that ranges from min. value of delta to max. value of delta and goes from red to violet.
This would mean that when I came to plot the data I could simply write:

subplot(111,projection="hammer")

p=plot([alpha],[beta],'o',mfc='delta')

where delta would represent a colour somewhere in the spectrum between red and violet. I.e if delta =0, the marker would be red and if delta =delta max. the marker would be violet and if delta =(delta. max)/2 the marker would be yellow.

Could anyone help me out with the syntax to do this?

Many thanks

Angela

Answer: 
If you are thinking of a fixed color table, just map your delta values into the index range for that table. For example, you can construct a color table with color names recognized by your plot package:

```
>>> colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']

```

The range of possible `delta` values, from your example, is `0` to `delta.max`. Mapping that to the length of the color tables, gives the `step`:

```
>>> step = delta.max / len(colors)

```

And the computation required to get a color name matching a given `data` point is:

```
>>> color = colors[math.trunc(data / step)]

```

This method works for any set of pre-selected colors, for example RGB values expressed as hex numbers.

A quick google search discovered [Johnny Lin's Python Library](http://www.johnny-lin.com/pylib.shtml). It contains [color maps](http://www.johnny-lin.com/cdat_tips/tips_color/new_cm.html), including [`Rainbow (red to violet, 790-380 nm)`](http://www.johnny-lin.com/cdat_tips/files/rainbow2.py).
You also need his [`wavelen2rgb.py`](http://www.johnny-lin.com/py_code/wavelen2rgb.py) (Calculate RGB values given the wavelength of visible light). Note that this library generates the colors as RGB triplets - you have to figure how your plotting library expects such color values.
Using the wavelen2rgb function of Johnny Lin's Python Library (as gimel suggested), the following code plots the SNs as filled circles. The code uses Tkinter which is always available with Python. You can get wavelen2rgb.py [here](http://www.johnny-lin.com/py_code/wavelen2rgb.py).

```
def sn():
    "Plot a diagram of supernovae, assuming wavelengths between 380 and 645nm."
    from Tkinter import *
    from random import Random
    root = Tk()                 # initialize gui
    dc = Canvas(root)           # Create a canvas
    dc.grid()                   # Show canvas
    r = Random()                # intitialize random number generator
    for i in xrange(100):       # plot 100 random SNs
        a = r.randint(10, 400)
        b = r.randint(10, 200)
        wav = r.uniform(380.0, 645.0)
        rgb = wavelen2rgb(wav, MaxIntensity=255)  # Calculate color as RGB
        col = "#%02x%02x%02x" % tuple(rgb)        # Calculate color in the fornat that Tkinter expects
        dc.create_oval(a-5, b-5, a+5, b+5, outline=col, fill=col) # Plot a filled circle
    root.mainloop()
sn()

```

Here's the outpout:

[alt text http://img38.imageshack.us/img38/3449/83921879.jpg](http://img38.imageshack.us/img38/3449/83921879.jpg)