Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save MATLAB figure with different background color

I want to print a MATLAB figure with a dark background and white labels. If I use the print or saveas command I lose somehow the colors. The plot symbols are dark again and the background is white.

points = rand(100,3);
plot3(points(:,1),points(:,2),points(:,3),'*w')
grid on
set(gca,'Color',[0.5 0.5 0.5])
saveas(gcf,'test1','pdf')
saveas(gcf,'test2','png')
print(gcf,'test3.pdf','-dpdf')

All three test files end up being wrong. If I choose "Save As" in the figure menu I am able to save the figure correctly.

Any ideas how to resolve the issue?

like image 331
Thomas Avatar asked Feb 03 '11 12:02

Thomas


People also ask

How do I change the background color of a figure in MATLAB?

Approach 1: a) From the File menu, select "Export setup". b) Under Properties select Rendering and check the “Custom color” option. c) Enter “w” in the adjacent text box and click “Apply to Figure” to update the figure.

How do I save a figure template in MATLAB?

Save Figure to File Save the figure to a file by first clicking Export, and then specifying a file name, location, and desired format. For more information about file formats, see saveas .

How do you get different colors in MATLAB?

Color Name or Short Name — Specify the name of a color such as "red" or "green" . Short names specify a letter from a color name, such as "r" or "g" . RGB Triplet — Create a custom color by specifying a three-element row vector whose elements are the intensities of the red, green, and blue components of a color.


1 Answers

To keep the background as in your figure, use the command set.

set(gcf, 'InvertHardCopy', 'off');

For adjusting the figure in other ways, check out this link

http://www.mathworks.com/help/techdoc/creating_plots/f3-84337.html

like image 128
Ghaul Avatar answered Oct 01 '22 03:10

Ghaul