Often you need to generate multiple figures with transparent background in order to put them directly into TeX document or presentation, but Matlab is prone to saving with white background using print

Problem:

Transparent vs non-transparent  background

Solution:

Use export_fig by Yair Altman.

“This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties

HOW TO

  1. Download the package from here (sign in if required)
  2. Unzip it and place to the folder with your project (rename it if needed e.g. to export_fig_folder)
  3. Add the folder to path by Right Click -> Add to path -> Selected folders and subfolders, or by adding addpath('./export_fig_folder/') to your script

Use function in the following manner:

Add set(gcf, 'Color', 'None') to your figure property or -transparent key when calling function

save_path = '../pics/MyPic';
export_fig(save_path, '-png', '-eps', '-transparent');

or:

export_fig ../pics/MyPic -png -eps -transparent;