Loading a texture image from file-like object

I would like to create scientific plots using matplotlib and then dynamically load the plots as a texture to be displayed on 3D geometry in Panda3D. I want to do this in memory, rather than saving the plot image to the hard drive and then loading the the texture from the file.

I imagine there is a way to do this but I’m not sure what approach to take. Matplotlib allows figures to be saved to a file-like object, I can use PIL to open the file-like object and access the pixel data. From there, I don’t know how to procedurally set or write the texture image data in Panda3d. Or is there another, better approach than this?

Any help much appreciated.

If im not mistaken the class for images, including textures, that panda uses is the PNMImage. Perhaps you can find a way to transfer your image into a PNMimage and apply that as your texture in the API: panda3d.org/reference/devel/ … MImage.php

Alternatively, you may use setRamImage (or setRamImageAs if it’s not in BGRA order) on Texture in order to pass the data as a packed string. Most image manipulation libraries have a method to get the data as a string.