save figure as eps from command line

14 次查看(过去 30 天)
pfb
pfb 2011-4-6
评论: pfb 2014-1-3
Hi all,
my goal is to produce eps files from my figs from command line. I can do this by issuing a command like
print(sprintf('-f%d',fh),'-dpsc2',name);
where fh is the figure handle and of courese name is the outptu filename. If I get it right this is basically how saveas work. However the appearance of the eps I get is different from what is obtained by using the dialog box popping up when the "save as" item of the "file" menu is chosen in the figure window. Typically print and saveas seem to ignore the changes I have made to alter the basic look of the figure (things like axis ticks, ticklabels, fontsizes and so on). Would it be possible to give a window command reproducing exactly the behaviour of "save as" from the figure menu?
The problem is that I find the menu choice a bit annoying, because I always have to re-save-as ".fig", or otherwise I risk loosing the changes I possibly make after creating the eps. Indeed saving through the "floppy-disk" button in the menu apparently applies to the last format chosen when "saving as".
Thanks a lot for any help
Francesco
  2 个评论
pfb
pfb 2011-4-7
Here is a simple way to expose the the problem, at least on the version of matlab I'm using.
1) Create a simple figure and embellish it a little, e.g. like this.
x=linspace(-0.8,0.8,101);y=x.^2;
plot(x,y);
xlabel('$x$','interpreter','latex','fontsize',18);
ylabel('$x^2$','interpreter','latex','fontsize',18);
set(gca,'fontsize',14); % increase font size
You should see the plot of a parabola. The axis ticks
are -1, -0.5, 0 , 0.5, 1 on the x axis and
0, 0.1, 0.2, ..., 0.7 on the y axis.
2) Export this figure as "menusaveas.eps" file via the "save as" item on the "file" menu of the figure window.
3) Export this figure using the builtin function, as suggested
by Tim (I changed the device to eps2c, type2 color eps).
saveas(gcf,'functionsaveas.eps','eps2c');
4) Compare the output files opening them e.g. via ghostview.
You should notice that the menusaveas.eps figure is basically
wysiwyg, whereas functionsaveas.eps is not. The bounding box
is different and, at least in my case, the xticks are different. If included in a tex-generated file, the fonts in the functionsaveas.eps figure will be smaller.
I am wondering what is matlab really doing the "menusaveas"
case. There should be some additional option to make the exported figure more wysiwyg, but so far I was not able to put my finger on it.
As I say, I have looked into saveas, and it seems to me that in this case it boils down to the command
print(gcf,'-dpsc2','functionsaveas.eps');
I also had a look in the package suggested by "the cyclist", and I am afraid that the eps is printed in the same way.
In that case a the eps is further "embellished" by some other functions. While I think that the package looks great, it seems to me that there should be a much easier way to reproduce the behaviour of the "save as" menu item from the command line.
Thanks a lot for any further comments
F
pfb
pfb 2014-1-3
Hi all,
having to use a windows system (hopefully) temporarily I stumbled once again on this problem. I performed a new search through matlab answers, and found a useful hint in this recent post. Apparently the "saveas problem" is related to the width and height in the PaperPosition property of the figure (more useful hints here).
I did some experimenting and the same fontsize is printed in different sizes depending on the PaperPosition w and h. I never thought of it, but it actually makes sense.
Apparently matlab "saveas" function chooses the xticks and yticks according to the PaperPosition as well, so it might happen that the axes labels in the eps are not the same as in the figure. It seems to me that explicitly setting the x and y ticks (possibly to the same values of the screen figures) prevents matlab to take the initiative on the labels (probably because some property is changed from 'auto' to 'manual').
I think that by setting the PaperPosition height and width, as well as the x and y ticks, I will be able to obtain a reasonably faithful eps file.
However I still do not understand why there is no simple command to obtain what the "file > save as >" dropdown menu does (Jan recently asked the same question, as probably many others did before).
This prompts another question: is there a way of knowing what script is linked to the "file > save as" dropdown menu in a figure?
Thanks
Francesco

请先登录,再进行评论。

回答(2 个)

the cyclist
the cyclist 2011-4-6
  1 个评论
pfb
pfb 2011-4-6
Hi! Thanks for the suggestion, I'll definitely look into that.
Cheers
Francesco

请先登录,再进行评论。


Tim Zaman
Tim Zaman 2011-4-6
standard fucntion.. saveas(h,'filename.eps','eps')
  1 个评论
pfb
pfb 2011-4-6
Hi tim, thanks for your suggestion.
As I mention, the "saveas" functions has exactly the same problem as my own function above. This is because, as far as I could understand from reading the "saveas" script, except for handling more formats, it basically does the same thing as my function.

请先登录,再进行评论。

类别

Help CenterFile 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