Matplotlib how to draw a picture on a PIL image

I have a new problem, I want to enter a PIL image object and then draw a shape created from matplotlib and then return the PIL image object. How could I achieve this?

+3
source share
1 answer

Why don't you create an image in matplotlib, save it and then import it into a file?

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())
+3
source

Source: https://habr.com/ru/post/1769674/


All Articles