I am using matplotlib and pygame to write to a framebuffer device which is a 160x128 LCD device.
When I plot the graph, save it to a PNG and the load it to the LCD, it looks perfect;
matplotlib.use('Agg')
TFTxSize = 2.28
TFTySize = 1.63
ax = fig.add_subplot(111)
fig.set_size_inches(TFTxSize, TFTySize)
pylab.plot(temp,linewidth=2, antialiased=True)
pylab.savefig('gp.png', facecolor=fig.get_facecolor(),bbox_inches='tight', dpi=80,pad_inches=0.03)
pil_im = Image.open('gp.png')
pil_out = pil_im.rotate(90)
pil_out.save("gp.png")
img = pygame.image.load('gp.png')
screen.blit(img,(0,0))
pygame.display.flip()
I was thinking of trying to do it more dynamically to save it to memory rather than writing a file. I found tried this;
canvas = agg.FigureCanvasAgg(fig)
canvas.draw()
renderer = canvas.get_renderer()
raw_data = renderer.tostring_rgb()
size = canvas.get_width_height()
surf = pygame.image.fromstring(raw_data, size, "RGB")
surfnew = pygame.transform.rotate(surf, 90)
screen.blit(surfnew, (0,0))
pygame.display.flip()
It does work, however it is a little bit larger…and I lost some of the formatting which I was able to do with the fist bit of code when saving it to disk. “bbox_inches='tight'” and “pad_inches=0.03” Any idea how to input these two formatting options in the bottom peace of code?