views:

52

answers:

1

I've got a new problem here, I wish to inputs a PIL image object, and then draw the figure that generated from matplotlib, and then return the PIL image object. How could I achieve this?

+3  A: 

Why don't you create the image in matplotlib, save it and then import it into pil?

xdata = pylab.arange(1961, 2031, 1)
pylab.figure(num=None, figsize=(20.48, 10.24), dpi=100, facecolor='w', edgecolor='k')
pylab.plot(xdata, ydata, linewidth=3.0)
pylab.xlabel(xlabel)
pylab.ylabel(ylabel)
pylab.title(title)
pylab.grid(True)

ram = cStringIO.StringIO()
pylab.savefig(ram, format='png')

import Image
im = Image.open(ram.read())
relima
the OP probably wants to overlay the graph on an existing image which is not addressed. I would either use the `pylab.savefig` with the `transparent` flag turned on and then combine the images in PIL, or I would describe how to use pylab's `imread`
bpowah