-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportfig.m
More file actions
83 lines (70 loc) · 2.17 KB
/
exportfig.m
File metadata and controls
83 lines (70 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function exportfig(figname, varargin)
%EXPORTFIG sets up a figure for export in publication format.
%
%usage:
%
% EXPORTFIG(figname)
%
%Without options, export the current figure and generates a pdf file
%based on figname.
%The default size is 8.4cm width by 6.5cm height, and is the standard single
%column JGR figure (in the good old format!).
%
% EXPORTFIG(figname, 'xSize', x, 'ySize', y)
%
%Using optional argument pairs 'xSize' and/or 'ySize' allows to change the
%figure size. Values must be in cm.
%
% EXPORTFIG(figname, 'hfig', h)
%
%Using optional argument pair 'hfig', h allows to use a given figure handle
%to save.
%
%input:
% figname: a string of character with the name of the figure.
% 'xSize', x: sets the figure width to x (in cm).
% 'ySize', y: sets the figure height to y (in cm).
% 'hfig', h: uses the figure handle h to export.
p = inputParser;
p.addRequired('figname', @ischar);
p.addParamValue('xSize', 8.4, @(x) isnumeric(x) && x>0);
p.addParamValue('ySize', 6.5, @(x) isnumeric(x) && x>0);
p.addParamValue('hfig', get(0,'CurrentFigure'), @ishandle);
p.parse(figname, varargin{:});
xSize = p.Results.xSize;
ySize = p.Results.ySize;
hfig = p.Results.hfig;
% plot
%find objects which have text:
htext = findall(hfig,'-property','FontName');
for k=1:length(htext)
set(htext(k), 'FontName', 'Times', ...
'FontSize',9);
end
set(hfig,'PaperUnits','centimeters');
%Additional coordinates to center the figure on A4-paper
xLeft = (21.0-xSize)/2;
yTop = (29.7-ySize)/2;
set(hfig,'PaperPosition',[xLeft yTop xSize ySize])
% save
filename = strcat(figname,'.eps');
if strfind(version, '2016')
%add .eps to make filename
filenametmp = strcat(figname,'_tmp.eps');
%print
print(hfig,'-depsc',filenametmp);
%fix hyphen
cmd = ['sed -e ''s/\/hyphen/\/endash/g'' -e ''s/[1[[:space:]]3][[:space:]]0[[:space:]]setdash/[2 2] 0 setdash/g'' ' filenametmp ' > ' filename];
system(cmd);
cmd = ['rm -f ' filenametmp];
system(cmd);
else
%print
print(hfig,'-depsc',filename);
fix_dottedline(filename);
end
%close(hfig);
cmd = ['ps2pdf -dEPSCrop -dAutoRotatePages=/None ' filename];
system(cmd);
cmd = ['rm -f ' filename];
system(cmd);