Save Figure Preserving Background Color

Retain Current Background Color

By default, saved figures have a white background. Ensure that the colors of the saved figure match the colors on the display by setting the InvertHardcopy property of the figure to 'off'. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

For example, create a bar chart and save it as a PNG file. Retain the figure background color in the saved output.

bar([1 10 7 8 2 2 9 3 6])
fig = gcf;
fig.InvertHardcopy = 'off';
saveas(gcf,'GrayBackground.png')

saveas saves the file, GrayBackground.png, in your current folder. The saved figure has the same gray background color as the onscreen figure.

Change Background Color

To change the figure color, set the Color property for the figure. For example, change the color to yellow before saving the figure.

bar([1 10 7 8 2 2 9 3 6])
fig = gcf;
fig.Color = 'yellow';
fig.InvertHardcopy = 'off';
saveas(gcf,'YellowBackground.png')

saveas saves the file, YellowBackground.png, in your current folder. The saved figure has the same yellow background color as the onscreen figure.

See Also

|

Related Topics