EPS export problems in R2014b

I have recently upgraded to R2014b (Linux version), and now exporting figures to eps seems to have a strange bug. If I try the following from the command line, I get the expected outcome. plot(1:3,2:4);print(gcf,'-depsc', 'testFromCommandLine.eps');
However, if I run the exact same script from the editor window, I get an eps file with a graph that occupies the top left corner of the canvas.
The only code in the script is: close all; plot(1:3,2:4); print(gcf,'-depsc', 'testFromScript.eps')
The screenshots of the two generated eps files are embedded.
This happens in all these three cases: pressing the RUN button in the editor, selecting the code and running the selection and executing the script (just typing the script's name without .m) from the command line.

2 个评论

This is definitely a Mathworks issue. I have access to both 2010b and 2014b--the following script behaves correctly in 2010b (saves an EPS graphic of the correct size) while in 2014b it tries to bound the graphic on a standard page size.
x = randn(10,1);
y = randn(10,1);
figure
set(gca,'FontSize',30)
set(gcf,'Units','normalized')
plot(x,y,'o')
title('Title','FontSize',30);
xlabel('X Label','FontSize',30)
ylabel('Y Label','FontSize',30)
set(gca,'box','on')
set(gcf,'OuterPosition',[0.1 0.1 0.7 0.7])
saveas(gcf,strcat('testfig','.fig'))
set(gcf,'PaperPositionMode','auto')
print('-depsc',strcat('testfig','.eps'))
close(gcf)
I am running OS X 10.9.5.
UPDATE: The following code will *almost* work (see comments below):
epsfig = hgexport('factorystyle');
epsfig.Format = 'eps';
x = randn(10,1);
y = randn(10,1);
figure
set(gca,'FontSize',30)
set(gcf,'Units','normalized')
plot(x,y,'o')
title('Title','FontSize',30);
xlabel('X Label','FontSize',30)
ylabel('Y Label','FontSize',30)
set(gca,'box','on')
set(gcf,'OuterPosition',[0.1 0.1 0.7 0.7])
saveas(gcf,strcat('testfig','.fig'))
set(gcf,'PaperPositionMode','auto')
hgexport(gcf,'filename',epsfig,'Format','eps')
close(gcf)
It appears that hgexport is a lower-level function used by the File > Save As command (hence explaining the observations of Remco). The file produced with the above code snippet renders OK on Mac (Mavericks). BUT: when the file is opened, it gives a warning about font conversion.
There are also some cross-platform issues. If you use latex symbols, e.g.,
title('\Delta Title','FontSize',30)
this will not render. Changing to
title('$\Delta$ Graphics','FontSize',30,'interpreter','latex');
will render fine on the Mac, but gives bizarre results (missing axis tick labels) on Windows (XP).
Basically, Mathworks needs to take a hard look at this. EPS graphics are near-universal for scientific publication, and if 2014b cannot do it properly, that is a major issue.

请先登录,再进行评论。

 采纳的回答

Can you check the 'PaperPositionMode' property of the figure before printing it in each case? Try setting it to 'auto' before printing:
>> set(gcf, 'PaperPositionMode','auto')
Do you see the same behavior when printing to something else than .eps, for example .png?
>> print -dpng test.png

5 个评论

Setting the 'PaperPositionMode' to 'auto' indeed did the trick. Just to be complete: I did not observe the same behavior when printing to png.
And I also observed a kind of randomness that I generally don't like: after opening Matlab this morning I could not to reproduce my own problem; I did get the normal figures when I ran my script for the first time. Only after running it a couple of times more, I experienced the same problem with the canvas size... Anyway, that's now irrelevant since the PaperPositionMode seems to work fine. Thanks for the help.
This might be due to the default value of 'PaperPositionMode'. Check the default value with:
>> get(groot, 'DefaultFigurePaperPositionMode')
You can change it to be 'auto' if it is not already:
>> set(groot, 'DefaultFigurePaperPositionMode','auto')
Unfortunately, it seems I have been too fast in concluding that setting the PaperPositionMode to auto was indeed solving my problem. Somehow it worked when I first tried it, but when running my scripts to produce my real graphs still gave me graphs that fill only part of the canvas. Even worse, after that I got the same wrongly formatted graphs as posted in my first post.
Setting groot doesn't help either.
Printing to png does not have the problem. Running the print command from the command line also does not have the problem.
I find it very strange that executing exactly the same code from the command line gives different results that running it from a script. Besides, I need to print many graphs, so doing everything from the commandline is not an option.
I hope the issue can be solved.
I am having the same problem. The following code worked fine in R2012a, but not in 2014b. When saving a figure that is wider than a page, the figure runs off of the printed page area (still 8.5"x11" even if I change it manually). I tried the 'PaperPositionMode' 'auto' trick above to no avail.
% Change paper units and figure units to inches
set(h, 'PaperUnits','inches')
set(h, 'Units','inches')
% Get current position of figure
pos = get(h,'Position');
% Set the paper size to match the figure
set(h, 'PaperSize', [pos(3) pos(4)]);
set(h, 'PaperPositionMode', 'manual');
set(h, 'PaperPosition',[0 0 pos(3) pos(4)]);
saveas(h, filename,'epsc')
where 'h' is the figure handle. Changing to 'pdf' instead of 'eps' or 'epic' seems to work fine, but I much prefer 'eps' because they are easier to work with in Adobe Illustrator for annotation.
Any solution is much appreciated.
I am having the same problem, too. It is infuriating, and making it impossible to proceed with writing a paper for a journal that only accepts vector figures.
Not to mention, the file sizes are outrageously huge in 2014 compared to 2012.

请先登录,再进行评论。

更多回答(7 个)

Jonathan
Jonathan 2014-10-24

2 个投票

Hi, I just upgraded to 2014b on OS X and neither of these fixes stops the .eps from being bounded by a full page when saved. I also tried changing groot as suggested, and even giving exact page sizes to match my figure window size but using either command line or script saving via saveas or print always returns the full page bounding box. Any other tips/things to try?
Using the dialog saveas works fine, why Matlab haven't implemented that as the default behaviour of saveas I have no idea.

1 个评论

Same here. I'm having the same problem and it is infuriating. Code which worked in 2012a now produces garbage pictures in 2014b. I've wasted hours and hours trying to get the old behavior back, to no avail. Also, the EPS files are now 10 times larger in file size than previous. Put it back the way it was!

请先登录,再进行评论。

CHJY
CHJY 2015-7-20

1 个投票

Try this:
  1. set(gcf,'paperpositionmode','auto')
  2. print(gcf,'-depsc2','-loose','test.eps');
The '-loose' option affects how matlab defines the bounding box in the eps file.

3 个评论

The -loose option fixed it for me! Thank you so much....
Wow, this solved the problem for me, I never would have known how to fix this.
Worked for me! Thank you Sir. Turns out MATLAB outputs tight bounding box that is inconsistent across different figures, so when I use epstopdf on them they are cropped to different dimensions!

请先登录,再进行评论。

Gideon simpson
Gideon simpson 2014-11-3

0 个投票

I have the additional problem on OS X 10.9 that when I save figure eps figures (with latex labels) and open them in Preview.app, I get:
PostScript Conversion Warning:
Converting the PostScript file "test.eps" produced the following warnings: · CMR10 not found, using Courier. · CMMI10 not found, using Courier.

1 个评论

I have the same problem, and have not been able to figure it out.

请先登录,再进行评论。

Viktor Vorobev
Viktor Vorobev 2015-2-15

0 个投票

I also have another problem. After exporting to EPS I used to edit the figure with CorelDRAW and everything was OK. But after exporting to EPS in 2014b (Win, x64), my CorelDRAW (X5, Win, x32) hangs while trying to import this EPS file.
With 2013b (Win, x64) everything works great.
PaVi90
PaVi90 2015-2-27

0 个投票

Same problem here. Is it possible that I have to downgrade to the blurry R2014a because of this? Unfortunately I desperately need exports in EPS in an automatic manner... :(
Daniel
Daniel 2015-6-25
编辑:Daniel 2015-6-25

0 个投票

This problem persists in Matlab 2015a. Code which previously generated a correctly sized eps no longer does so. Instead, I get a letter-sized eps containing a fragment of my figure, with the box spilling over the edge. Hence, the visualization software I wrote is essentially broken for generating publication-quality vector graphics. A fix is desperately sought.
Shannon
Shannon 2017-11-23

0 个投票

Still having the same issues with 2016.

1 个评论

@Shannon: I find several problem descriptions and suggestions for solutions. Please explain, what exactly "the same issue" is, preferably with a small code example.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Printing and Saving 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by