-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrepareFigure.m
653 lines (564 loc) · 30.6 KB
/
PrepareFigure.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
function PrepareFigure(figureNumber, varargin)
% Adjust a figure to some predecided aspect ratio. Set the axis font,
% ticks and tick labels and the change the plot properties and save the
% figure as a single eps file or uses tikz to create an eps and tex
% file.
%
% Mandotory input arguments:
% figureNumber: Figure number of the figure to be prepared
%
% Optional arguments:
% The optional arguments are entered using 'PropertyName' and
% 'PropertyValue'. See below for possible properties and values.
%
% Examples of useage:
% PrepareFigure(1);
% PrepareFigure(gcf);
% PrepareFigure(gcf,'PropertyName','PropertyValue')
%
% PropertyName PropertyValue Description
% 'fileName' <file_name> A string variable. Default: 'figure', filename of saved figure
% 'figSize' 'max'|'portrait'|[x,y,xextent,yextent] A 4 x 1 integer vector for the figure's x, y, postion and xlength and ylength in pixels.
% Set to 'max' to maximise figure to current screen or 'portriat' for portrait mode. Default: [90,70,1100,600].
% 'markerSize' #1 An real number to set the figure marker size
% 'tikz' Call this property without a property value to save the figure as a .tikz file and in the .tex file use
% set{\figureheight}{ycm} \set{\figurewidth}{xcm} \input(<file_name>.tikz), May need LuaLaTex if the size is too big.
% Need matlab2tikz function (From Matlab central)
% 'pdf' Call this property without a property value to save the figure as pdf so that pdfLaTex can be used
% Need export_fig function (From Matlab central)
% 'Beamer' Call this property without a property value to make figure for beamer with black background
% 'PowerPoint' Call this property without a property value to make a figure suitable for a Power Point presentation.
% 'Word' Call this property without a property value to make a figure suitable for a Word document.
% 'Poster' Call this property without a property value to make a figure suitable for a poster
% 'noSave' Call this property to only prepare figure but not save the figure in any foramt. Used to first adjust and then add annotations
%
% The following properties, nAxes, nPlots and nProps must be sepcified together,
% it can be used to change properties of plots in a certain axis.
%
% 'nAxes' [#1,#2,...] A integer vector variable indiciating the axes of the plots.
% 'nPlots' {[],[],...} A cell variable, where each element is a vector of the plots
% whose propeties will be changed, number of vectors or size of nPlots
% must equal to number of axes or size of nAxes.
% 'nProps' {{},{},...} A cell variable, with cell elements, and each inner cell specifies the
% standard Matlab 'property', 'value' of the plot function. Number of inner
% cells must be equal to total number of plots specified in nPlots
% 'axisFontSize' #1 To overide defalut axis value
% 'labelFontSize' #1 To overide defalut axis value
% 'annotationFontSize' #1 To overide defalut axis value
% 'LineWidth' #1 To overide default Line width
%
% Example useage with nAxes, nPlots and nProps.
% For example if you want to change the color and marker of the 1st plot in
% axis 1 and the marker size of the 2nd plot in axes 2 (assuming
% there are two axes), you can invoke PrepareFigure as follows:
% PrepareFigure(1,'nAxes',[1,2],'nPlots',{[1],[2]},'nProps',{{'color','red','Marker','o'},{'MarkerSize',12}}),
%
% W.D. Widanage 16-09-2012 (Lazy Sunday, listening to Metallica)
%% Set fonts for axes, labels, legends and annotations as wished
axisFont = 'Times New Roman';
axisFontWeight = 'Normal'; % Axis font weight, 'Light', 'Normal, 'Demi','Bold'
axisFontAngle = 'Normal'; % Axis font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'axisFontSize')==1); % Axis font size in points
if isempty(idx)
axisFontSize = 16;
else
axisFontSize = varargin{idx+1};
end
axisFontColour = 'black'; % Axis font colour
axisBgColour = 'white'; % Axis background colour
labelFontWeight = 'Normal'; % Label font weight, 'Light', 'Normal, 'Demi','Bold'
labelFontAngle = 'Normal'; % Label font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'labelFontSize')==1); % Label font size in points
if isempty(idx)
labelFontSize = 18;
else
labelFontSize = varargin{idx+1};
end
labelFontColour = 'black'; % Label font colour
legendFontSize = 16; % Legend font size in points
legendFontColour = 'black'; % Legend font colour
idx = find(strcmp(varargin,'annotationFontSize')==1);% Annotation font size in points
if isempty(idx)
annotationFontSize = 18;
else
annotationFontSize = varargin{idx+1};
end
annotationFontWeight = 'Normal'; % Annotation font weight, 'Light', 'Normal, 'Demi','Bold'
annotationFontAngle = 'Normal'; % Annotation font angle, 'Normal, 'Italic','Oblique'
annotationFontColour = 'black'; % Annotation (arrow, line) colour
interpreter = 'Tex'; % Set interpreter, Tex, Latex or None
textFontSize = 20; % Set any text font size
defAxisSize = [0.13,0.21,0.775,0.650]; % Use this as default axis postion and size if only one plot, multiple plots uses matlab default
defFigSize = [90,70,1100,600]; % Default figure postion and size
portFigSize = [90,70,800,900]; % Portrait figure postion and size
idx = find(strcmp(varargin,'LineWidth')==1); % Line width
if isempty(idx)
LineWidth = 2; % Use this as default line width for all plots
else
LineWidth = varargin{idx+1};
end
idx = find(strcmp(varargin,'markerSize')==1); % Axis font size in points
if isempty(idx)
MarkerSize = 6; % Use this as default marker size for Beamer plots
else
MarkerSize = varargin{idx+1};
end
legendLineWidth = 1; % Use this as default for line width in legends
legendMarkerSize = 8; % Use this as default for the marker size in legends
BoxOnOff = 'off'; % Set to off to remove to and right edges of axes box
TickDirInOut = 'out'; % Set ticks (mini dashes) in axes to be outwards or inwards
XGridOnOff = 'off'; % Set horizontal grids to on or off
YGridOnOff = 'off'; % Set vertical grids to on or off
% Settings for Beamer
idxBeamer = find(strcmp(varargin,'Beamer')==1); % Check for Beamer argument
if isempty(idxBeamer)
else
axisFont = 'Times New Roman';
axisFontWeight = 'Normal'; % Axis font weight, 'Light', 'Normal, 'Demi','Bold'
axisFontAngle = 'Normal'; % Axis font angle, 'Normal, 'Italic','Oblique'
axisFontColour = 'white'; % Axis font colour
idx = find(strcmp(varargin,'axisFontSize')==1); % Axis font size in points
if isempty(idx)
axisFontSize = 16;
else
axisFontSize = varargin{idx+1};
end
axisBgColour = [0.094, 0.094, 0.094]; % Axis background colour % Black-grey
labelFontWeight = 'Normal'; % Label font weight, 'Light', 'Normal, 'Demi','Bold'
labelFontAngle = 'Normal'; % Label font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'labelFontSize')==1); % Label font size in points
if isempty(idx)
labelFontSize = 16;
else
labelFontSize = varargin{idx+1};
end
labelFontColour = 'white'; % Label font colour
legendFontSize = 16; % Legend font size in points
legendFontColour = 'white'; % Legend font colour
idx = find(strcmp(varargin,'annotationFontSize')==1);% Annotation font size in points
if isempty(idx)
annotationFontSize = 14;
else
annotationFontSize = varargin{idx+1};
end
annotationFontWeight = 'Normal'; % Annotation font weight, 'Light', 'Normal, 'Demi','Bold'
annotationFontAngle = 'Normal'; % Annotation font angle, 'Normal, 'Italic','Oblique'
annotationFontColour = 'white'; % Annotation font and arrow box colour
interpreter = 'Latex'; % Set interpreter, Tex, Latex or None
textFontSize = 10; % Set any text font size
defAxisSize = [0.13,0.21,0.775,0.650]; % Use this as default axis postion and size if only one plot, multiple plots uses matlab default
defFigSize = [90,90,1100,650]; % Default figure postion and size
portFigSize = [90,70,500,900]; % Portrait figure postion and size
idx = find(strcmp(varargin,'LineWidth')==1); % Line width
if isempty(idx)
LineWidth = 1.5; % Use this as default line width for all plots
else
LineWidth = varargin{idx+1};
end
idx = find(strcmp(varargin,'markerSize')==1); % Axis font size in points
if isempty(idx)
MarkerSize = 5; % Use this as default marker size for Beamer plots
else
MarkerSize = varargin{idx+1};
end
legendLineWidth = 1; % Use this as default for line width in legends
legendMarkerSize = 8; % Use this as default for the marker size in legends
end
% Settings for a Power Point slide
idxPpt = find(strcmp(varargin,'PowerPoint')==1); % Check for PowerPoint argument
if isempty(idxPpt)
else
axisFont = 'Bahnschrift';
axisFontWeight = 'Normal'; % Axis font weight, 'Light', 'Normal, 'Demi','Bold'
axisFontAngle = 'Normal'; % Axis font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'axisFontSize')==1); % Axis font size in points
if isempty(idx)
axisFontSize = 20;
else
axisFontSize = varargin{idx+1};
end
axisFontColour = 'black'; % Axis font colour
axisBgColour = 'white'; % Axis background colour
labelFontWeight = 'Normal'; % Label font weight, 'Light', 'Normal, 'Demi','Bold'
labelFontAngle = 'Normal'; % Label font angle, 'Normal, 'Italic','Oblique
idx = find(strcmp(varargin,'labelFontSize')==1);% Label font size in points
if isempty(idx)
labelFontSize = 20;
else
labelFontSize = varargin{idx+1};
end
labelFontColour = 'black'; % Label font colour
legendFontSize = 14; % Legend font size in points
legendFontColour = 'black'; % Legend font colour
idx = find(strcmp(varargin,'annotationFontSize')==1);% Annotation font size in points
if isempty(idx)
annotationFontSize = 14;
else
annotationFontSize = varargin{idx+1};
end
annotationFontWeight = 'Normal'; % Annotation font weight, 'Light', 'Normal, 'Demi','Bold'
annotationFontAngle = 'Normal'; % Annotation font angle, 'Normal, 'Italic','Oblique'
annotationFontColour = 'black'; % Annotation (arrow, line) colour
interpreter = 'tex'; % Set interpreter, Tex, Latex or None
defAxisSize = [0.13,0.15,0.775,0.770]; % Use this as default axis postion and size if only one plot, multiple plots uses matlab default
defFigSize = [90,70,1100,600]; % Default figure postion and size
portFigSize = [90,70,800,900]; % Portrait figure postion and size
idx = find(strcmp(varargin,'LineWidth')==1); % Line width
if isempty(idx)
LineWidth = 3; % Use this as default line width for all plots
else
LineWidth = varargin{idx+1};
end
idx = find(strcmp(varargin,'markerSize')==1); % Axis font size in points
if isempty(idx)
MarkerSize = 6; % Use this as default marker size for Beamer plots
else
MarkerSize = varargin{idx+1};
end
legendLineWidth = 1; % Use this as default for line width in legends
legendMarkerSize = 8; % Use this as default for the marker size in legends
end
% Settings for a Word document
idxWord = find(strcmp(varargin,'Word')==1); % Check for Word argument
if isempty(idxWord)
else
axisFont = 'Times New Roman';
axisFontWeight = 'Normal'; % Axis font weight, 'Light', 'Normal, 'Demi','Bold'
axisFontAngle = 'Normal'; % Axis font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'axisFontSize')==1); % Axis font size in points
if isempty(idx)
axisFontSize = 20;
else
axisFontSize = varargin{idx+1};
end
axisFontColour = 'black'; % Axis font colour
axisBgColour = 'white'; % Axis background colour
labelFontWeight = 'Normal'; % Label font weight, 'Light', 'Normal, 'Demi','Bold'
labelFontAngle = 'Normal'; % Label font angle, 'Normal, 'Italic','Oblique
idx = find(strcmp(varargin,'labelFontSize')==1);% Label font size in points
if isempty(idx)
labelFontSize = 25;
else
labelFontSize = varargin{idx+1};
end
labelFontColour = 'black'; % Label font colour
legendFontSize = 14;%12;%14; % Legend font size in points
legendFontColour = 'black'; % Legend font colour
idx = find(strcmp(varargin,'annotationFontSize')==1);% Annotation font size in points
if isempty(idx)
annotationFontSize = 20;
else
annotationFontSize = varargin{idx+1};
end
annotationFontWeight = 'Normal'; % Annotation font weight, 'Light', 'Normal, 'Demi','Bold'
annotationFontAngle = 'Normal'; % Annotation font angle, 'Normal, 'Italic','Oblique'
annotationFontColour = 'black'; % Annotation (arrow, line) colour
interpreter = 'Tex'; % Set interpreter, Tex, Latex or None
defAxisSize = [0.13,0.15,0.775,0.770]; % Use this as default axis postion and size if only one plot, multiple plots uses matlab default
defFigSize = [90,70,1100,600]; % Default figure postion and size
portFigSize = [90,70,800,900]; % Portrait figure postion and size
idx = find(strcmp(varargin,'LineWidth')==1); % Line width
if isempty(idx)
LineWidth = 2; % Use this as default line width for all plots
else
LineWidth = varargin{idx+1};
end
idx = find(strcmp(varargin,'markerSize')==1); % Axis font size in points
if isempty(idx)
MarkerSize = 6; % Use this as default marker size for Beamer plots
else
MarkerSize = varargin{idx+1};
end
legendLineWidth = 1; % Use this as default for line width in legends
legendMarkerSize = 8; % Use this as default for the marker size in legends
end
% Settings for a A0 Poster document
idxPoster = find(strcmp(varargin,'Poster')==1); % Check for Poster argument
if isempty(idxPoster)
else
axisFont = 'Times New Roman';
axisFontWeight = 'Normal'; % Axis font weight, 'Light', 'Normal, 'Demi','Bold'
axisFontAngle = 'Normal'; % Axis font angle, 'Normal, 'Italic','Oblique'
idx = find(strcmp(varargin,'axisFontSize')==1); % Axis font size in points
if isempty(idx)
axisFontSize = 20;
else
axisFontSize = varargin{idx+1};
end
axisFontColour = 'black'; % Axis font colour
axisBgColour = 'white'; % Axis background colour
labelFontWeight = 'Normal'; % Label font weight, 'Light', 'Normal, 'Demi','Bold'
labelFontAngle = 'Normal'; % Label font angle, 'Normal, 'Italic','Oblique
idx = find(strcmp(varargin,'labelFontSize')==1);% Label font size in points
if isempty(idx)
labelFontSize = 122;
else
labelFontSize = varargin{idx+1};
end
labelFontColour = 'black'; % Label font colour
legendFontSize = 18; % Legend font size in points
legendFontColour = 'black'; % Legend font colour
idx = find(strcmp(varargin,'annotationFontSize')==1);% Annotation font size in points
if isempty(idx)
annotationFontSize = 18;
else
annotationFontSize = varargin{idx+1};
end
annotationFontWeight = 'Normal'; % Annotation font weight, 'Light', 'Normal, 'Demi','Bold'
annotationFontAngle = 'Normal'; % Annotation font angle, 'Normal, 'Italic','Oblique'
annotationFontColour = 'black'; % Annotation (arrow, line) colour
interpreter = 'Tex'; % Set interpreter, Tex, Latex or None
defAxisSize = [0.13,0.15,0.775,0.770]; % Use this as default axis postion and size if only one plot, multiple plots uses matlab default
defFigSize = [90,70,1100,600]; % Default figure postion and size
portFigSize = [90,70,800,900]; % Portrait figure postion and size
idx = find(strcmp(varargin,'LineWidth')==1); % Line width
if isempty(idx)
LineWidth = 1; % Use this as default line width for all plots
else
LineWidth = varargin{idx+1};
end
idx = find(strcmp(varargin,'markerSize')==1); % Axis font size in points
if isempty(idx)
MarkerSize = 6; % Use this as default marker size for Beamer plots
else
MarkerSize = varargin{idx+1};
end
legendLineWidth = 1; % Use this as default for line width in legends
legendMarkerSize = 8; % Use this as default for the marker size in legends
end
%% Get variable input arguments and set to default if uninitialised
% Check for a given file name
idx = find(strcmp(varargin,'fileName')==1);
if isempty(idx)
fileName = 'figure'; % Set file name to default
else
fileName = varargin{idx+1};
end
% Check for a given figure resolution
idx = find(strcmp(varargin,'figSize')==1);
if isempty(idx)
set(figureNumber,'Position',defFigSize); % Set figure position and ascpect ration to default
else
figSize = varargin{idx+1};
if strcmp(figSize,'max')
rootUnits = get(0,'Units'); % Get current screen units
scrRes = get(0,'ScreenSize'); % Get current screen resolution
set(figureNumber,'Position',scrRes,'Units',rootUnits) % Set figure postion and aspect ratio to maximum screen size
elseif strcmp(figSize,'portrait')
set(figureNumber,'Position',portFigSize) % Set figure postion and aspect ratioportrait size
else
set(figureNumber,'Position',figSize) % Set figure postion and aspect ratio to give figure size
end
end
% Check for tikz input
idx = find(strcmp(varargin,'tikz')==1);
if isempty(idx)
useTikz = 0; % Set useTikz to default
else
useTikz = 1; % Set useTikz value to given value
end
% Check for pdf input
idx = find(strcmp(varargin,'pdf')==1);
if isempty(idx)
usePDF = 0; % Set usePDF to default
else
usePDF = 1; % Set usePDF value to given value
end
% Check noSave input
idx = find(strcmp(varargin,'noSave')==1);
if isempty(idx)
useSave = 1; % Set useSave to 0
else
useSave = 0; % Set useSave to 0
end
% Graph properties
% Check for plot properties: First get the axes of the plots
idx = find(strcmp(varargin,'nAxes')==1);
if isempty(idx)
nAxes = []; % Set nAxes to default
else
nAxes = varargin{idx+1}; % Set nAxes value to given value
end
% Check for plot properties: Now get the plots
idx = find(strcmp(varargin,'nPlots')==1);
if isempty(idx)
nPlots = []; % Set nPlots to default
else
nPlots = varargin{idx+1}; % Set nPlots value to given value
end
% Check for plot properties: Now get the plot properties
idx = find(strcmp(varargin,'nProps')==1);
if isempty(idx)
nProps = []; % Set nProps to default
else
nProps = varargin{idx+1}; % Set nProps value to given value
end
%% For a given figure edit each axes, legend, annotations and all plots within an axis
% Set figure background colour
set(figureNumber,'Color',axisBgColour);
% Get number of axis in figure
hAxes = get(figureNumber,'Children');
totalAxes = numel(hAxes);
% Edit text properties. This needs to be done pror to changing X and
% Ylabels text
set(groot,'ShowHiddenHandles','on')
hText = findobj('type','text');
try % Edit text in arrow annotations
set(hText,...
'FontName' , axisFont,...
'FontSize' , textFontSize,...
'FontWeight', annotationFontWeight,...
'FontAngle', annotationFontAngle,...
'Color', annotationFontColour,...
'Interpreter',interpreter);
catch
end
set(groot,'ShowHiddenHandles','off')
if totalAxes == 1
set(hAxes,'Position',defAxisSize)
end
% Change axes font size and axes properties
for aa = 1: totalAxes
set(hAxes(aa), ...
'FontName' , axisFont ,...
'FontSize' , axisFontSize,...
'FontWeight', axisFontWeight,...
'FontAngle', axisFontAngle,...
'Box' , BoxOnOff , ...
'TickDir' , TickDirInOut, ...
'TickLength', [.007 .007] , ...
'XMinorTick', 'off' , ...
'YMinorTick', 'off' , ...
'XGrid' , XGridOnOff , ...
'YGrid' , YGridOnOff ,...
'Color', axisBgColour, ...
'XColor', axisFontColour, ...
'YColor', axisFontColour)
% Set X,Y and Title
% Change xlabel font, font size, weight and angle
hXlabel = hAxes(aa).XLabel;
set(hXlabel,...
'FontName',axisFont,...
'Interpreter',interpreter,...
'FontSize',labelFontSize,...
'FontWeight',labelFontWeight,...
'FontAngle',labelFontAngle);
% Change xlabel font, font size, weight and angle
hYlabel = hAxes(aa).YLabel;
set(hYlabel,...
'FontName',axisFont,...
'Interpreter',interpreter,...
'FontSize',labelFontSize,...
'FontWeight',labelFontWeight,...
'FontAngle',labelFontAngle);
% Change xlabel font, font size, weight and angle
hTitle = hAxes(aa).Title;
set(hTitle,...
'FontName',axisFont,...
'Interpreter',interpreter,...
'FontSize',labelFontSize,...
'FontWeight',labelFontWeight,...
'FontAngle',labelFontAngle);
try
% Edit plot thickness and marker size
hPlots = flipud(get(hAxes(aa),'Children'));
for pp = 1:numel(hPlots)
set(hPlots(pp), ...
'LineWidth', LineWidth);
set(hPlots(pp), ...
'MarkerSize', MarkerSize);
end
catch
end
end
% Edit annotation properties
set(groot,'ShowHiddenHandles','on')
hAnnotations = findobj('type','textarrow');
try % Edit text in arrow annotations
set(hAnnotations,...
'FontName' , axisFont,...
'FontSize' , annotationFontSize,...
'FontWeight', annotationFontWeight,...
'FontAngle', annotationFontAngle,...
'TextColor' , annotationFontColour,...
'Color', annotationFontColour,...
'Interpreter', interpreter,...
'HorizontalAlignment','center',...
'TextLineWidth', 1,...
'HeadLength' , 6,...
'HeadWidth' , 6,...
'HeadStyle' ,'vback1');
catch
end
% Edit text box properties
hBox = findobj('type','textbox');
try % Edit text in textbox annotations
set(hBox,...
'FontName' , axisFont,...
'FontSize' , annotationFontSize,...
'FontWeight', annotationFontWeight,...
'FontAngle', annotationFontAngle,...
'Color' , annotationFontColour,...
'EdgeColor', annotationFontColour,...
'Interpreter', interpreter,...
'HorizontalAlignment','center',...
'LineStyle','none');
catch
end
% Edit text box properties
hText = findobj('type','text');
% try % Edit text in textbox annotations
% set(hText,...
% 'FontName' , axisFont,...
% 'FontSize' , annotationFontSize,...
% 'FontWeight', annotationFontWeight,...
% 'FontAngle', annotationFontAngle,...
% 'Color' , annotationFontColour,...
% 'EdgeColor', annotationFontColour,...
% 'Interpreter', interpreter,...
% 'HorizontalAlignment','center',...
% 'LineStyle','none');
% catch
% end
% Edit double end arrow properties
hBox = findobj('type','DoubleEndArrow');
set(hBox,...
'Color' , annotationFontColour);
set(groot,'ShowHiddenHandles','off')
% Get legend handle
legendHandles = findobj(figureNumber,'Tag','legend'); % Get the handles of the legend axes
% Edit legend properties and remove legend handles from axesHandles to get the xy axes handles
for ii = 1: length(legendHandles) % Loop over each legend
idx = axesHandles == legendHandles(ii);
axesHandles(idx) = [];
% Change legend properties
set(legendHandles(ii),...
'FontName', axisFont,... % Change legend font
'FontSize', legendFontSize,... % Change legend font size
'Interpreter', interpreter); % Set legend interpreter to Latex
% Get the string handles of within each legend
legendStringHandle_temp = get(legendHandles(ii),'Children');
lengthTemp = length(legendStringHandle_temp);
for jj = 1: lengthTemp/3 % Every thrid handle is the string handle, the other two are line handles
legendStringHandle = legendStringHandle_temp(jj*3);
idxText = textHandles == legendStringHandle; % Find the corresponding text handle in the string handle and delete
textHandles(idxText) = [];
set(legendStringHandle_temp(jj*3-1),'LineWidth',legendLineWidth); % Set legend line width
set(legendStringHandle_temp(jj*3-2),'MarkerSize',legendMarkerSize); % Set marker size
end
end
% Save file as an eps
if useSave
if useTikz
matlab2tikz('figurehandle',figureNumber,[fileName,'.tex'], 'height', '\figureheight', 'width', '\figurewidth','showInfo',false);
elseif usePDF
export_fig(figureNumber, fileName, '-pdf', '-transparent') % Save as a pdf
elseif ~isempty(idxBeamer)
export_fig(figureNumber, fileName, '-pdf', '-transparent') % Save as a pdf
elseif isempty(idxPpt) && isempty(idxWord) % An eps figure is not created when prepared for Power Point or Word
set(figureNumber,'PaperPositionMode','auto')
print(figureNumber,'-depsc2',fileName) % Save as an eps
disp(['Figure is saved with filename: ',fileName,'.eps']);
end
savefig(figureNumber,fileName); % Also save the .fig file
end