Looper
Looper

Reputation: 364

Difference between print/saveas and export

I'm doing some plots in Matlab, but when exporting to pdf I'm not getting the same results I see on my screen. In particular, I'm trying to put white edges to the legend.

leg1 = legend(names);
set(leg1,'EdgeColor',[1 1 1]);

When using "File -> Save As -> Out.pdf" the edges are white, but when I use saveas(gca,'Out.pdf') or print -dpdf Out.pdf the edges are black. What is Matlab doing when I use the export function? How can I have the same results from the command line?


Edit

Just to be clear, this is an example code:

plot(rand(10,1))
leg1 = legend('Data');
set(leg1,'EdgeColor',[1 1 1]);
print -dpdf Out.pdf

The pdf file shows this: enter image description here

Which clearly is not the intended figure, and its different from the one showed by Matlab. When I use the "File -> Save as" option, the edge of the label is displayed correctly.

Upvotes: 1

Views: 3006

Answers (2)

Zhe
Zhe

Reputation: 2132

I am afraid that the other answer does not really answer the question. This is how you "print" white line/text to a file: run

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

before using the print command.

However, for your specific case, since you are just trying to hide the box borders, the better way to do it is

legend boxoff

or

legend('boxoff')

Source: https://www.mathworks.com/matlabcentral/answers/102484-why-does-my-white-text-become-black-in-my-figure-when-printing-to-an-emf-file-in-matlab-7-5-r2007b

Upvotes: 1

matlabgui
matlabgui

Reputation: 5672

When saving from the "File -> Save As " it runs an mfile filemenufcn.

You can call it diretly from the commandline:

filemenufcn ( figHandle, 'FileSaveAs' )

Its a shame Mathworks don't allow you to pass in a filename to save directly...

You can investigate that function to see what the function is doing to the figure before its being saved.

FYI: In the latest Matlab (R2015a) the final code that does the actual saving to pdf is hgexport. (Which is a p-code file but it does have some basic help) You could directly invoke that at the commandline.

You should also look at export_fig which is an excellent tool for exporting graphics to file.

Upvotes: 2

Related Questions