On Nov 12, 2009, at 4:32 PM, Jae-Joon Lee wrote:
> shape = fig.canvas.get_width_height()[::-1] + (4,)
>
> im = np.frombuffer(fig.canvas.buffer_rgba(0,0),
> dtype=np.uint8).reshape(shape)
>
> Using buffer_rgba is more efficient than using tostring_rgb as no
> memory is allocated. B
On Thu, Nov 12, 2009 at 6:32 PM, Geoffrey Ely wrote:
> Thanks for the help. With that I get:
>
> AttributeError: 'function' object has no attribute '__buffer__'
>
>
shape = fig.canvas.get_width_height()[::-1] + (4,)
im = np.frombuffer(fig.canvas.buffer_rgba(0,0),
dtype=np.uint
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
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 )
might work -- something like that, anyway.
-CHB
--
Christopher Bark
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