[ase-users] Plot to matplotlib subplot

Magnus Nord magnus.nord at glasgow.ac.uk
Fri Jun 3 10:27:27 CEST 2016


Hey,

I'm trying to make plots of several atomic structures within the same 
matplotlib figure, where they each can have a different orientation or 
structure.

After digging around in the ase.io.eps and png modules I managed to make 
a function which does this:

from ase.io.png import PNG

def get_rgba_image_array(ase_atoms_object, **parameters):
     png_plot = PNG(ase_atoms_object, **parameters)
     png_plot.write_header()
     png_plot.write_body()
     rgba_buffer = png_plot.renderer.buffer_rgba()
     image_data = np.frombuffer(rgba_buffer, np.uint8)
     image_data = image_data.reshape(int(png_plot.h),int(png_plot.w),4)
     return(image_data)

image_data = get_rgba_image_array(slab, radii=radii)
ax.imshow(image_data)

However, this does not work optimally, as it is plotting the raster 
output potentially leading to low-res images.

So I am wondering if there is an easier way of doing this?

And, if there isn't: would there be any interest in having such 
functionality? For example a get_matplotlib_figure(ase_atoms_object) 
which returns a figure and/or subplots of the structure, where if a 
subplot or figure is given to the function, the structure is plotted in 
the given figure and/or subplot.

It would be fairly straight forward to implement this, since all the 
plotting code is already in the ase.io.eps module.

Magnus


More information about the ase-users mailing list