-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakeitPretty.m
237 lines (210 loc) · 5.29 KB
/
MakeitPretty.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
function MakeitPretty(FigureHandle, FigureProperties, AxisProperties, PlotProperties, OutputFile)
%MAKEITPRETTY Graphical Modification Function
%
% Make it Pretty function
% Written by Mojtaba Mansour Abadi
%
% Using this MATLAB function, shit gets in, a butterfly goes out!
% If you don't believe, it's OK, no one cares.
%
% To use the function, plot your figure and type:
% MakeitPretty(FH, [FW, FL], [XS, YS], [FS, LW, MS, AS], FN)
%
% FH = Figure handle, you can enter 'gcf' if you are dealing with one figure only.
%
% FW = desired figure width.
% FL = desired figure height.
%
% XS = desired X axis style: N = linear, G = logarithmic
% YS = desired Y axis style: N = linear, G = logarithmic
%
% FS = desired Text font size.
% LW = desired line width.
% MS = desired marker size.
% AS = desired axes label size
%
% FN = desired file name
%
% Example:
% X = 1:0.1*pi:2*pi;
% hold on;
% plot(X, sin(X), 'b-');
% plot(X, cos(X), 'k-*');
% xlabel('t');
% ylabel('f(t)');
% legend('sin', 'cos');
% MakeitPretty(gcf, [300, 400], 'LNLG', [16, 2.5, 16, 10], 'Figure');
%
% That's it.
Const_TS = 0.75;
Const_TL = [2, 1]*0.01;
Def_FS = 16.0;
Def_AS = 10.0;
Def_XS = 'linear';
Def_YS = 'log';
Def_LW = 1.5;
Def_MS = 5.0;
Def_FW = 10.0;
Def_FL = 9.0;
Def_FN = 'Figure';
switch nargin
case 0
FH = gcf;
FS = Def_FS;
LW = Def_LW;
MS = Def_MS;
AS = Def_AS;
FW = Def_FW;
FL = Def_FL;
XS = Def_XS;
YS = Def_YS;
FN = Def_FN;
case 1
FH = FigureHandle;
FS = Def_FS;
LW = Def_LW;
MS = Def_MS;
AS = Def_AS;
FW = Def_FW;
FL = Def_FL;
XS = Def_XS;
YS = Def_YS;
FN = Def_FN;
case 2
FH = FigureHandle;
T1 = FigureProperties;
FW = T1(1);
FL = T1(2);
XS = Def_XS;
YS = Def_YS;
FS = Def_FS;
LW = Def_LW;
MS = Def_MS;
AS = Def_AS;
FN = Def_FN;
case 3
FH = FigureHandle;
T1 = FigureProperties;
FW = T1(1);
FL = T1(2);
T2 = AxisProperties;
if T2(1) == 'G'
XS = 'log';
else
XS = 'linear';
end
if T2(2) == 'G'
YS = 'log';
else
YS = 'linear';
end
FS = Def_FS;
LW = Def_LW;
MS = Def_MS;
AS = Def_AS;
FN = Def_FN;
case 4
FH = FigureHandle;
T1 = FigureProperties;
FW = T1(1);
FL = T1(2);
T2 = AxisProperties;
if T2(1) == 'G'
XS = 'log';
else
XS = 'linear';
end
if T2(2) == 'G'
YS = 'log';
else
YS = 'linear';
end
T3 = PlotProperties;
FS = T3(1);
LW = T3(2);
MS = T3(3);
AS = T3(4);
FN = Def_FN;
case 5
FH = FigureHandle;
T1 = FigureProperties;
FW = T1(1);
FL = T1(2);
T2 = AxisProperties;
if T2(1) == 'G'
XS = 'log';
else
XS = 'linear';
end
if T2(2) == 'G'
YS = 'log';
else
YS = 'linear';
end
T3 = PlotProperties;
FS = T3(1);
LW = T3(2);
MS = T3(3);
AS = T3(4);
FN = OutputFile;
end
set(FH, 'Color', [1, 1, 1])
% set(FH, 'Resize', 'off');
set(FH, 'RendererMode', 'auto');
set(FH, 'Renderer', 'painters');
OBJ = findobj(FH, 'type', 'axes');
for Index = 1:length(OBJ)
AX1 = OBJ(Index);
% AX1 = get(FH, 'CurrentAxes');
set(AX1, 'XMinorTick', 'on');
set(AX1, 'YMinorTick', 'on');
set(AX1, 'ZMinorTick', 'on');
set(AX1, 'FontName','Times New Roman');
set(AX1, 'FontSize', FS);
set(AX1, 'Box', 'on');
set(AX1, 'XScale', XS);
set(AX1, 'YScale', YS);
set(AX1, 'LineWidth', Const_TS);
set(AX1, 'TickLength', Const_TL);
XL = get(AX1, 'XLabel');
set(XL, 'FontName','Times New Roman');
set(XL, 'FontSize', FS);
YL = get(AX1, 'YLabel');
set(YL, 'FontName','Times New Roman');
set(YL, 'FontSize', FS);
ZL = get(AX1, 'ZLabel');
set(ZL, 'FontName','Times New Roman');
set(ZL, 'FontSize', FS);
set(AX1, 'FontSize', AS);
end
root = get(FH, 'Parent');
% OBJ = get(AX, 'Children');
OBJ = findobj(FH, 'type', 'line');
for child = OBJ
set(child, 'LineWidth', LW);
set(child, 'MarkerSize', MS);
end
set(root, 'ShowHiddenHandles', 'on');
ANN = findobj(FH, 'type', 'hggroup');
for annot = ANN
if(~isprop(annot, 'LineWidth'))
continue;
end
set(annot, 'LineWidth', LW);
end
for annot = ANN
if(~isprop(annot, 'FontName'))
continue;
end
set(annot, 'FontName','Times New Roman');
set(annot, 'FontSize', FS);
end
OBJ = findobj(FH, 'type', 'text');
for child = OBJ
set(child, 'FontName','Times New Roman');
set(child, 'FontSize', FS);
end
set(root, 'ShowHiddenHandles', 'off');
set(FH, 'paperunits', 'centimeters', 'paperposition', [0, 0, FW, FL]);
print(FH, '-djpeg', '-r600', FN);
return;