Hi, What is the best way to rasterize a figure into a numpy array for further image processing? The code I have below works, but I am wondering if there is a more convenient way.

Thanks in advance, Geoff

import pylab, numpy

fig = pylab.figure()

pylab.plot( [1, 2, 1] )

dpi = fig.get_dpi()

size = fig.get_size_inches()

shape = size[1] * dpi, size[0] * dpi, 3

image = fig.canvas.renderer.tostring_rgb()

image = numpy.fromstring( image, 'u1' ).reshape( shape )

pylab.imshow( image )