-
Notifications
You must be signed in to change notification settings - Fork 29
/
show_plot.m
115 lines (106 loc) · 4.34 KB
/
show_plot.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
function [] = show_plot(gen, pop, varargin)
% This function plots the front, stolen from KeLi and Zhanghu's code.
% gen = generation count
% pop = population at generation gen
% optional parameters:
% is_text = will show values for each point on the plot, boolean
% xlist = list of variables to be plotted for the pareto set
% flist = list of objectives to plot, when nobj > 3
global nreal ;
global nobj ;
p = inputParser;
addRequired(p, 'gen', @isnumeric);
addRequired(p, 'pop', @ismatrix);
addOptional(p, 'is_text', false, @islogical);
addOptional(p, 'xlist', [], @(x) isvector(x) || isempty(x));
addOptional(p, 'flist', [], @(x) isvector(x) || isempty(x));
addOptional(p, 'xlim_', [], @(x) isvector(x) || isempty(x));
addOptional(p, 'ylim_', [], @(x) isvector(x) || isempty(x));
addOptional(p, 'zlim_', [], @(x) isvector(x) || isempty(x));
parse(p, gen, pop, varargin{:});
if(nobj == 2)
f = p.Results.pop(:, nreal + [1 2]);
elseif(isempty(p.Results.flist))
f = p.Results.pop(:, nreal + [1 2 3]);
flist = [1 2 3] ;
else
f = p.Results.pop(:, nreal + p.Results.flist);
flist = p.Results.flist ;
end
if(~isempty(p.Results.xlist))
xlist = p.Results.xlist ;
x = p.Results.pop(:, nreal + xlist);
end
fstr = sprintf('objective space, gen = %d', p.Results.gen);
xstr = sprintf('variable space, gen = %d', p.Results.gen);
if(p.Results.gen == 1)
if(~isempty(p.Results.xlist))
cpos = get(gcf, 'Position');
set(gcf,'Position',[cpos(1) cpos(2) 1000 400]);
end
end
hold off;
if(~isempty(p.Results.xlist))
subplot(1,2,1);
end
% plot objectives
if nobj == 2
plot(f(:,1), f(:,2), 'ro', 'MarkerSize', 4);
xlabel('f1', 'FontSize', 6);
ylabel('f2', 'FontSize', 6);
if(~isempty(p.Results.xlim_)); xlim(p.Results.xlim_); end;
if(~isempty(p.Results.ylim_)); ylim(p.Results.ylim_); end;
if(p.Results.is_text)
strValues = strtrim(cellstr(num2str([f(:,1) f(:,2)],'(%.4f,%.4f)')));
text(f(:,1), f(:,2), strValues, 'VerticalAlignment', 'bottom');
end
else
plot3(f(:,1), f(:,2), f(:,3), ...
'ro', 'MarkerSize', 4);
xlabel(sprintf('f%d', flist(1)), 'FontSize', 6);
ylabel(sprintf('f%d', flist(2)), 'FontSize', 6);
zlabel(sprintf('f%d', flist(3)), 'FontSize', 6);
if(~isempty(p.Results.xlim_)); xlim(p.Results.xlim_); end;
if(~isempty(p.Results.ylim_)); ylim(p.Results.ylim_); end;
if(~isempty(p.Results.zlim_)); zlim(p.Results.zlim_); end;
if(p.Results.is_text)
strValues = strtrim(cellstr(num2str([f(:,1) f(:,2) f(:,3)],...
'(%.4f,%.4f,%.4f)')));
text(f(:,1), f(:,2), f(:,3), ...
strValues, 'VerticalAlignment', 'bottom');
end
end
title(fstr, 'FontSize', 8);
box on;
drawnow;
% plot variables
if(~isempty(p.Results.xlist))
subplot(1,2,2);
if(length(xlist) == 2)
plot(x(:,1), x(:,2), 'ro', 'MarkerSize', 4);
xlabel('x1', 'FontSize', 6);
ylabel('x2', 'FontSize', 6);
if(p.Results.is_text)
strValues = strtrim(cellstr(num2str([x(:,1) x(:,2)],...
'(%.4f,%.4f)')));
text(x(:,1), x(:,2), strValues, ...
'VerticalAlignment', 'bottom');
end
else
plot3(x(:,1), x(:,2), x(:,3), ...
'ro', 'MarkerSize', 4);
xlabel(sprintf('x%d', xlist(1)), 'FontSize', 6);
ylabel(sprintf('x%d', xlist(2)), 'FontSize', 6);
zlabel(sprintf('x%d', xlist(3)), 'FontSize', 6);
if(p.Results.is_text)
strValues = strtrim(cellstr(...
num2str([x(:,1) x(:,2) x(:,3)],...
'(%.4f,%.4f,%.4f)')));
text(x(:,1), x(:,2), x(:,3), ...
strValues, 'VerticalAlignment', 'bottom');
end
end
title(xstr, 'FontSize', 8);
box on;
drawnow;
end