imtools.imwrite

imtools.imwrite(figobj, fstr, dpi=None)[source]

Save a Matplotlib figure camera-ready using a “tight” bounding box

Parameters:

figobj : Matplotlib figure

Matplotlib figure object to be saved

fstr : string

String holding the filename to be used to save the figure. If a specific file format is wanted, provide it with fstr, e.g., fstr = ‘output.tiff’. If fstr does not contain a filename extension the Matplotlib default (png) will be used.

dpi : integer

The wanted resolution of the output in dots per inch. If None the Matplotlib default will be used.

Returns:

Nothing : None

See also

savefig
in the Matplotlib documentation

Notes

This is a humble attempt to get rid of the huge white areas around plots that are generated by Matplotlib’s savefig when saving a figure as an image using default values. It tries to mimic export_fig for MATLAB. The result, however, is not perfect yet...