/
formatfig.m
executable file
·74 lines (66 loc) · 2.68 KB
/
formatfig.m
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
function hfigout = formatfig(hfig,varargin)
%FORMATFIG format figures for publications (figname is used to set automatically the name and the filename)
% syntax: formatfig
% formatfig(hfig,'figname',figname,'property1',value1,'property2',value2,'property3',value3,..)
% hfig = formatfig(...)
% hs: axes handles (default = all handles in the current figure)
% property/value any valid axes properties
% property 'figname' codes for the name of the file (' ' and ':' are replaced respectively by '_' and '-')
% MS 2.1 - 28/12/09 - INRA\Olivier Vitrac - rev. 31/08/15
% Revision history
% 22/04/11 force case sensitive values (required for filename on Linux)
% 04/09/11 replace ifig by hfig(ifig) for figure numbering
% 08/01/15 new color scheme for defaultAxesColorOrder based R2014b http://fr.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html
% 28/02/15 add Tag
% 12/03/15 add hfigout
% 31/08/15 update 'Number' as it is fixed now by Mathworks
arg_default = struct(...
'figname' ,sprintf('fig_%s',datestr(now)),...
'Tag','',...
'PaperUnits','Centimeters',...
'PaperType','A4',...
'PaperOrientation','Portrait',...
'PaperPositionMode','manual',...
'Units','pixels',...
'defaultAxesColorOrder',[
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840
] ...
);
% arg check
if nargin<1, hfig = []; end
if isempty(hfig)
children = get(0,'children');
hfig = children(strcmp(get(children,'type'),'figure'));
hfig = hfig(end:-1:1);
end
if isempty(hfig), hfig = gcf; end
[arg,remain] = argcheck(varargin,arg_default,[],[],'case');
arg.figname(arg.figname==' ')='_';
arg.figname(arg.figname==':')='-';
% set attributes to figure(s)
set(hfig,rmfield(arg,'figname'))
if ~isempty(remain)
try set(hfig,remain{:})
catch, error('invalid additional (figure) arguments')
end
end
nfig = length(hfig);
% change the name in the titlebar
if ~isempty(arg.figname)
for ifig=1:nfig
if verLessThan('matlab','8.4')
% before 4/9/11: set(hfig(ifig),'Name',sprintf('%0.2d: %s',ifig,arg.figname),'FileName',arg.figname,'NumberTitle','off')
set(hfig(ifig),'Name',sprintf('%0.2d: %s',hfig(ifig),arg.figname),'FileName',arg.figname,'NumberTitle','off')
else % 'Number' has been fixed by Matworks
set(hfig(ifig),'Name',sprintf('%0.2d: %s',get(hfig(ifig),'Number'),arg.figname),'FileName',arg.figname,'NumberTitle','off')
end
end
end
% output
if nargout, hfigout = hfig; end