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 )

------------------------------------------------------------------------------
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

Reply via email to