I need a little help. I have a chart that is produced with matplotlib, and the last requirement is to display the company logo (.PNG file) on the chart. However, I cannot use the Python Image Library (PIL) for this task and so am using pypng to read the logo, but after much searching, I cannot find a way to convert the image to a matplotlib 'compatible' one for use with figmimage (to overlay the logo on the chart).
The pypng docs show how to convert an image using numpy for use with matplotlib, but their examples are Python 2.x and I don't know how to convert the example (itertools.imap) for use with Python 3).
Here's what I have so far:
import png
import numpy
from matplotlib.figure import Figure
fig = Figure(figsize=(8.5, 4.1))
r = png.Reader('/home/jm/Desktop/logo.png')
r.read()
rows, cols, pngdata, d = r.asFloat()
rows=28, cols=500, d['planes']=4 There are 500 columns because I think this the png is in RGBA format, ie. 4 values per pixel rows.
# My poor attempt to map the pypng image to numpy
img = numpy.reshape(pngdata, (rows, cols, d['planes']))
fig.figimage(img, 0, 0)
I get garbage pixels on the chart in case you're wondering... I've read the docs, but I'm clearly missing something, but I don't know WHAT.
ANY help would be appreciated!
Thanks,
JM