ptypy.utils.plot_utils.imsave#
- ptypy.utils.plot_utils.imsave(a, filename=None, vmin=None, vmax=None, cmap=None)#
Take array a and transform to PIL.Image object that may be used by pyplot.imshow for example. Also save image buffer directly without the sometimes unnecessary Gui-frame and overhead.
- Parameters:
a (ndarray) – Two dimensional array. Can be complex, in which case the amplitude will be optionally clipped by vmin and vmax if set.
filename (str, optionsl) – File path to save the image buffer to. Use ‘*.png’ or ‘*.png’ as image formats.
vmin (float, optional) – Value limits (‘clipping’) to fit the color scale. If not set, color scale will span from minimum to maximum value in array
vmax (float, optional) – Value limits (‘clipping’) to fit the color scale. If not set, color scale will span from minimum to maximum value in array
cmap (str, optional) – Name of the colormap for colorencoding.
- Returns:
im – a PIL.Image object.
- Return type:
PIL.Image
See also
Examples
>>> from ptypy.utils import imsave >>> from matplotlib import pyplot as plt >>> from ptypy.resources import flower_obj >>> a = flower_obj(512) >>> pil = imsave(a) >>> plt.imshow(pil) >>> plt.show()
converts array a into, and returns a PIL image and displays it.
>>> pil = imsave(a, /tmp/moon.png)
returns the image and also saves it to filename
>>> imsave(a, vmin=0, vmax=0.5)
clips the array to values between 0 and 0.5.
>>> imsave(abs(a), cmap='gray')
uses a matplotlib colormap with name ‘gray’