<p>下面的代码使用Johnny Lin的Python库的wavelon2rgb函数(正如gimel所建议的那样),将SNs绘制成填充圆。代码使用了Python中始终可用的Tkinter。你可以得到小波2rgb.py<a href="http://www.johnny-lin.com/py_code/wavelen2rgb.py" rel="nofollow noreferrer">here</a>。在</p>
<pre><code>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()
</code></pre>
<p>输出如下:</p>
<p><a href="http://img38.imageshack.us/img38/3449/83921879.jpg" rel="nofollow noreferrer">alt text http://img38.imageshack.us/img38/3449/83921879.jpg</a></p>