This is an issue with how Preview on Mac OS X renders EPS files that is exposed by a change in the way that MATLAB R2014b formats the EPS file. MATLAB R2014b places the "bounding box" values at the end of the EPS file while previous versions of MATLAB placed the "bounding box" values at the beginning of the file. MATLAB R2014b is using a valid format, however, Preview on Mac OS X seems to not recognize this format.
One workaround is to use the postscript 2 flag ('psc2' for color or 'ps2' for black and white). These flags can be used with both the 'print' and 'saveas' commands, but when used with the 'print' command you need to prefix the flag with '-d'. When you use one of these flags, the resulting EPS file will have a paper size that is equal to the value of the 'PaperSize' parameter in the exported figure. In order to set the 'PaperSize' so that it crops the exported image to tight bounds, you can set it equal to the 'width' and 'height' of the image. Please see the sample code below that details how to do this.
>> f1 = figure;
>> surf(peaks);
>> D = f1.PaperPosition;
>> f1.PaperSize = [D(3) D(4)];
>> saveas(f1,'Peaks1.eps','psc2');
>> print -f1 -dpsc2 Peaks2.eps
When executing this code, two EPS files will be generated that will display the same image that is cropped to the image size.
4 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_249263
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_249263
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263805
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263805
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263806
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263806
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263817
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/162283-why-is-the-figure-in-my-eps-file-generated-using-matlab-r2014b-in-the-wrong-position-and-with-extra#comment_263817
Sign in to comment.