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:
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.
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.