Skip to content

Commit 439c524

Browse files
committed
Generate first plots
1 parent 925116a commit 439c524

File tree

3 files changed

+1041
-0
lines changed

3 files changed

+1041
-0
lines changed

barvalues.m

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
function varargout = barvalues(h,precision)
2+
% barvalues;
3+
% barvalues(h)
4+
% barvalues(h,precision)
5+
% t = barvalues(h,precision)
6+
%
7+
% Display bar values ontop of bars in bar plot.
8+
%
9+
% h - handle to axes or bar (operates on specified object only)
10+
% or figure (operates on all desndant bars).
11+
% (default:gca)
12+
% precision - Decimal precision to display (0-10),
13+
% or 'formatSpec' as in num2str. (default:'% .0f')
14+
% t - handles to the text objects.
15+
16+
%Author: Elimelech Schreiber, 11/2017
17+
% ver 1.3
18+
19+
t=[];
20+
21+
if nargin>1 && ~isempty(precision) % Parse precision
22+
if isnumeric(precision) && precision >=0 && precision <=10
23+
precision =['% .',int2str(precision),'f'];
24+
elseif ~ischar(precision) && ~isstring(precision)
25+
error('Precision format unsupported.');
26+
end
27+
else
28+
precision ='% .1f';
29+
end
30+
31+
if nargin<1 || isempty(h) % parse h (handle)
32+
h =gca;
33+
elseif isaType(h,'figure')
34+
B =findobj(h,'type','bar'); % apply to multiple axes in figure.
35+
for b =B'
36+
t = [t; {barvalues(b,precision)}]; % Return array of text objects
37+
% for each bar plot.
38+
end
39+
if nargout>0
40+
varargout{1}=t;
41+
end
42+
return;
43+
end
44+
if isaType(h,'axes')
45+
h =findobj(h,'type','bar');
46+
if isempty(h)
47+
return; % silently. to support multiple axes in figure.
48+
end
49+
end
50+
if ~isaType(h,'bar')
51+
error('Cannot find bar plot.');
52+
end
53+
54+
for hn =h'
55+
56+
axes(ancestor(hn,'axes')); % make intended axes curent.
57+
if isfield(hn,'XOffset')&&~isempty(hn.XOffset), XOffset = hn.XOffset; else XOffset = 0; end
58+
if isfield(hn,'YOffset')&&~isempty(hn.YOffset), YOffset = hn.YOffset; else YOffset = 0; end
59+
xData = hn.XData +XOffset; yData = hn.YData +YOffset;
60+
61+
t = [t; text(xData,yData,... %position
62+
arrayfun(@(x)num2str(x,precision),yData,'UniformOutput' ,false),... %text to display
63+
'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',18)];
64+
end
65+
if nargout>0
66+
varargout{1}=t;
67+
end
68+
69+
function flag =isaType(h,type)
70+
try
71+
flag =strcmp(get(h, 'type'), type);
72+
catch
73+
flag =false;
74+
end
75+
76+
77+
function flag = isfield(h,fld)
78+
flag =true;
79+
try
80+
get(h,fld);
81+
catch
82+
flag =false;
83+
end

generate_plots.m

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
%
2+
% Generate Some Nice Plots for my transpalette
3+
%
4+
clear all
5+
close all
6+
clc
7+
8+
FontSize= 18;
9+
10+
11+
%
12+
% CSV formatted as follows:
13+
%
14+
% NCC,NSC2,NSC3,NSC5,NN,P-BP,P-MSE
15+
% line1: scores on original data
16+
% line2: execution times on original data
17+
% line3: scores on pca data
18+
% line4: execution times on pca data
19+
%
20+
performance_MNIST = dlmread('scores_and_times_MNIST.csv', ',');
21+
performance_ORL = dlmread('scores_and_times_ORL.csv', ',');
22+
performance_MNIST = performance_MNIST(:,1:end-1);
23+
performance_ORL = performance_ORL(:,1:end-1);
24+
25+
%
26+
% CSV formatted as follows:
27+
%
28+
% line1: Labels
29+
% line2: Dimension 1
30+
% line3: Dimension 2
31+
32+
%data_pca_MNIST = dlmread('/path/to/pca_data_MNIST',',');
33+
%data_pca_ORL = dlmread('/path/to/pca_data_ORL',',');
34+
35+
36+
37+
38+
%% Performance Bar Plots
39+
% Original Data
40+
fig_MNIST = figure('units','normalized','outerposition',[0 0 1 1]);
41+
c = {'NC','NSC2','NSC3','NSC5','NN','P-BP','P-MSE'};
42+
bar(performance_MNIST(1,:))
43+
barvalues;
44+
ylim([0 120]);
45+
set(gca,'xticklabel',c)
46+
set(gca,'FontSize',FontSize);
47+
ylabel('Success Rate [%]','FontSize',FontSize)
48+
grid on
49+
50+
51+
fig_ORL = figure('units','normalized','outerposition',[0 0 1 1]);
52+
c = {'NC','NSC2','NSC3','NSC5','NN','P-BP','P-MSE'};
53+
bar(performance_ORL(1,:))
54+
barvalues;
55+
ylim([0 120]);
56+
set(gca,'xticklabel',c)
57+
set(gca,'FontSize',FontSize);
58+
ylabel('Success Rate [%]','FontSize',FontSize)
59+
grid on
60+
61+
%% Performance Plots
62+
fig_performance = figure('units','normalized','outerposition',[0 0 1 1]);
63+
64+
h=semilogy(performance_MNIST(1,:),performance_MNIST(2,:),'x',...
65+
performance_ORL(1,:),performance_ORL(2,:),'o');
66+
lgd = legend('MNIST','ORL','Location','NW');
67+
lgd.FontSize = FontSize;
68+
l = {'NC','NSC2','NSC3','NSC5','NN','P-BP','P-MSE'};
69+
labelpoints(performance_MNIST(1,:),performance_MNIST(2,:),l,'N','FontSize',FontSize);
70+
labelpoints(performance_ORL(1,:),performance_ORL(2,:),l,'N','FontSize',FontSize);
71+
set(h(1),'MarkerSize',12,'Linewidth',3);
72+
set(h(2),'MarkerSize',12,'Linewidth',3);
73+
set(gca,'FontSize',FontSize);
74+
ylabel('Execution Time [ms]','FontSize',FontSize)
75+
xlabel('Success Rate [%]','Fontsize',FontSize)
76+
grid on
77+
78+
fig_performance_pca = figure('units','normalized','outerposition',[0 0 1 1]);
79+
80+
h=semilogy(performance_MNIST(3,:),performance_MNIST(4,:),'x',...
81+
performance_ORL(3,:),performance_ORL(4,:),'o');
82+
lgd = legend('MNIST','ORL','Location','NW');
83+
lgd.FontSize = FontSize;
84+
l = {'NC','NSC2','NSC3','NSC5','NN','P-BP','P-MSE'};
85+
labelpoints(performance_MNIST(3,:),performance_MNIST(4,:),l,'N','FontSize',FontSize);
86+
labelpoints(performance_ORL(3,:),performance_ORL(4,:),l,'N','FontSize',FontSize);
87+
set(h(1),'MarkerSize',12,'Linewidth',3);
88+
set(h(2),'MarkerSize',12,'Linewidth',3);
89+
set(gca,'FontSize',FontSize);
90+
ylabel('Execution Time [ms]','FontSize',FontSize)
91+
xlabel('Success Rate [%]','Fontsize',FontSize)
92+
grid on
93+
94+
%% PCA Data Plots
95+
96+
% MNIST
97+
for i =1:10
98+
% Split data into classes
99+
idx = find(data_pca_MNIST(1,:) == i-1);
100+
s{i} = data_pca_MNIST(2:3,idx);
101+
end
102+
fig_mnist_pca = figure('units','normalized','outerposition',[0 0 1 1]);
103+
plot(s{1}(1,:),s{1}(2,:),'+',...
104+
s{2}(1,:),s{2}(2,:),'o',...
105+
s{3}(1,:),s{3}(2,:),'*',...
106+
s{4}(1,:),s{4}(2,:),'.',...
107+
s{5}(1,:),s{5}(2,:),'x',...
108+
s{6}(1,:),s{6}(2,:),'s',...
109+
s{7}(1,:),s{7}(2,:),'d',...
110+
s{8}(1,:),s{8}(2,:),'^',...
111+
s{9}(1,:),s{9}(2,:),'v',...
112+
s{10}(1,:),s{10}(2,:),'>');
113+
grid on
114+
115+
% ORL
116+
for i =1:40
117+
idx = find(data_pca_ORL(1,:) == i);
118+
s{i} = data_pca_ORL(2:3,idx);
119+
end
120+
fig_orl_pca = figure('units','normalized','outerposition',[0 0 1 1]);
121+
122+
plot(s{1}(1,:),s{1}(2,:),'+',...
123+
s{2}(1,:),s{2}(2,:),'o',...
124+
s{3}(1,:),s{3}(2,:),'*',...
125+
s{4}(1,:),s{4}(2,:),'.',...
126+
s{5}(1,:),s{5}(2,:),'x',...
127+
s{6}(1,:),s{6}(2,:),'s',...
128+
s{7}(1,:),s{7}(2,:),'d',...
129+
s{8}(1,:),s{8}(2,:),'^',...
130+
s{9}(1,:),s{9}(2,:),'v',...
131+
s{10}(1,:),s{10}(2,:),'<',...
132+
s{11}(1,:),s{11}(2,:),'>',...
133+
s{12}(1,:),s{12}(2,:),'p',...
134+
s{13}(1,:),s{13}(2,:),'h',...
135+
s{14}(1,:),s{14}(2,:),'+',...
136+
s{15}(1,:),s{15}(2,:),'o',...
137+
s{16}(1,:),s{16}(2,:),'*',...
138+
s{17}(1,:),s{17}(2,:),'.',...
139+
s{18}(1,:),s{18}(2,:),'x',...
140+
s{19}(1,:),s{19}(2,:),'s',...
141+
s{20}(1,:),s{20}(2,:),'d',...
142+
s{21}(1,:),s{21}(2,:),'^',...
143+
s{22}(1,:),s{22}(2,:),'v',...
144+
s{23}(1,:),s{23}(2,:),'>',...
145+
s{24}(1,:),s{24}(2,:),'<',...
146+
s{25}(1,:),s{25}(2,:),'p',...
147+
s{26}(1,:),s{26}(2,:),'h',...
148+
s{27}(1,:),s{27}(2,:),'+',...
149+
s{28}(1,:),s{28}(2,:),'o',...
150+
s{29}(1,:),s{29}(2,:),'*',...
151+
s{30}(1,:),s{30}(2,:),'.',...
152+
s{31}(1,:),s{31}(2,:),'x',...
153+
s{32}(1,:),s{32}(2,:),'s',...
154+
s{33}(1,:),s{33}(2,:),'d',...
155+
s{34}(1,:),s{34}(2,:),'^',...
156+
s{35}(1,:),s{35}(2,:),'v',...
157+
s{36}(1,:),s{36}(2,:),'>',...
158+
s{37}(1,:),s{37}(2,:),'<',...
159+
s{38}(1,:),s{38}(2,:),'p',...
160+
s{39}(1,:),s{39}(2,:),'h',...
161+
s{40}(1,:),s{40}(2,:),'+');
162+
grid on
163+
164+
165+
%% Save
166+
mkdir('plots')
167+
% Print to .eps file for nice latex integration
168+
print(fig_performance, 'plots/comparison_performance','-depsc');
169+
print(fig_performance_pca, 'plots/comparison_performance_pca','-depsc');
170+
print(fig_mnist_pca, 'plots/mnist_pca_plot','-depsc');
171+
print(fig_orl_pca, 'plots/orl_pca_plot','-depsc');

0 commit comments

Comments
 (0)