On Nov 12, 2009, at 2:01 PM, Christopher Barker wrote:
> Geoffrey Ely wrote:
>> Hi, What is the best way to rasterize a figure into a numpy array for
>> further image processing?
>
> untested, but I suspect:
>> image =  
>> numpy.frombuffer( fig.canvas.renderer.buffer_rgba).reshape( shape )

Thanks for the help. With that I get:

AttributeError: 'function' object has no attribute '__buffer__'


I found a cleaner way to get the shape, so this is getting better:

shape = fig.canvas.get_width_height()[::-1] + (3,)
image = numpy.fromstring( fig.canvas.renderer.tostring_rgb(),  
'u1' ).reshape( shape )

-Geoff

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