Re: [Matplotlib-users] Converting figure to numpy array

2009-03-24 Thread Christopher Barker
John Hunter wrote: > Perhaps we should make this a friendly helper method of the agg backend > canvas -- canvas.toarray() returns an rgba numpy array via > canvas.buffer_rgba? +1 -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(206) 52

Re: [Matplotlib-users] Converting figure to numpy array

2009-03-24 Thread John Hunter
On Tue, Mar 24, 2009 at 10:46 AM, Jae-Joon Lee wrote: > canvas = gcf().canvas > buf = canvas.tostring_rgb() > > img = numpy.fromstring(buf, numpy.uint8) > im_size = canvas.get_width_height() > rgb = img.reshape(im_size[1], im_size[0], 3) > r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2] > Perhaps

Re: [Matplotlib-users] Converting figure to numpy array

2009-03-24 Thread Jae-Joon Lee
canvas = gcf().canvas buf = canvas.tostring_rgb() img = numpy.fromstring(buf, numpy.uint8) im_size = canvas.get_width_height() rgb = img.reshape(im_size[1], im_size[0], 3) r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2] Or if you're using PIL, pil_image = PIL.Image.fromstring("RGB", im_size, buf)

[Matplotlib-users] Converting figure to numpy array

2009-03-24 Thread Philipp Lies
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I want to convert the current figure to a numpy array w/o saving the image to disk. I need this to convert a matlab function to python, the original code is: F = getframe(gcf); X = frame2im(F); My current workaround is h = gcf() h.savefig('tmp.pn