Для этого вам может понадобиться Python PIL: http://effbot.org/imagingbook/pil-index.htm
Вот простой пример, который поможет вам начать работу после установки PIL:
import Image, ImageDraw
import math
# Create image, giving size and background color
im = Image.new("RGB", (400,400), (0, 128, 128) )
# You will do your drawing in the image through the 'draw' object
draw = ImageDraw.Draw(im)
def f(x):
return math.sin(3*x)
# One loop alongside the line
for i in xrange( 400 ):
# and another if you need a different width
for j in xrange( 196, 204 ):
# Calculate an x-value in the range 0-1. This is a hack
# you might need something more general.
x = i / 400.0
c = f(x)
# And calculate the colors from there
red = int( 256*(1.0-c) )
blue = 256 - red
im.putpixel( ( i, j ), (red, 0, blue) )
im.save("test.png", "PNG")
КонечноЯ бы не рекомендовал вышеупомянутый подход для чего-либо, требующего производительности, но этого может быть достаточно, чтобы вы не спешили.