Why is the figure in my EPS file generated using MATLAB R2014b in the wrong position and with extra white space when viewed in Mac Preview, even though I set PaperPositionMode to 'auto'?

7 Ansichten (letzte 30 Tage)
If I generate an EPS file in MATLAB R2014b as follows:
>> f1 = figure;
>> surf(peaks);
>> f1.PaperPositionMode = 'auto';
>> print -f1 -depsc Peaks.eps
When I open the output EPS file in Preview on Mac OS X, the figure is shown at the bottom-left corner. The EPS file generated with the same code using MATLAB R2014a is shown at the center, as it should be when 'PaperPositionMode' is set to 'auto'.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 24 Okt. 2014
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; % Returns 1x4 vector [left right width height]
>> f1.PaperSize = [D(3) D(4)]; %default PaperSize is [8.5 11]
>> 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.

Weitere Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Produkte


Version

R2014b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by