-
Notifications
You must be signed in to change notification settings - Fork 0
/
f_colorspaceRepBars.m~
122 lines (85 loc) · 3.86 KB
/
f_colorspaceRepBars.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
function f_colorspaceRepBars(matches, roundvec, dataname)
% function colorspaceRepBars(matches, binning, dataname)
% meant to show you the ratio of observed matches to expected matches for a
% given bin in rgb space given the assumption of uniform random matches
% matches are nx26x3 matrix of matches
% roundvec bins the rgb space into managable size
% dataname puts a name on the figure and could be used for saving
% useful for plots
letters = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'};
% counts of letters in each rounded 3d bin across all letters
allletterhists = zeros((length(roundvec))^3,1);
% rounded rgb values across all letters
allroundedclrs = [];
clrctr = 1;
% for each letter
for i=1:26
clrs = squeeze(matches(:,i,:));
% all rgb values are between 0 and 1
% we could round to the nearest .1
% use downloaded function roundtowardvec
% roundvec = 0:.25:1; %(1331 locations)
roundedclrs = roundtowardvec(clrs,roundvec);
allroundedclrs = [allroundedclrs; roundedclrs];
% want to be able to scale our plots (either alpha or markersize) using the
% number of datapoints in each bin. 3d hist code in matlab looks like a
% pain so we could do it in a loop?
counter=1;
bplotmatrix = zeros(length(roundvec)^3,4);
for a=1:length(roundvec)
for b=1:length(roundvec)
for c=1:length(roundvec)
bplotmatrix(counter,:) = [roundvec(a) roundvec(b) roundvec(c) ...
sum(ismember(roundedclrs, [roundvec(a) roundvec(b) roundvec(c)],...
'rows'))];
counter=counter+1;
end
end
end
% less than a minute
% collect matches for this letter for all letters plot
allletterhists = allletterhists + bplotmatrix(:,4);
% uniform matches at each point
expectedmatches = sum(bplotmatrix(:,4))/(length(roundvec))^3;
% for the bar plot we need to sort the bplotmatrix
[sorted sortindex] = sort(bplotmatrix(:,4));
% so for each letter if we want it later
% figure('name',['distribution across rgb space for ' dataname ' ' letters{i}],'Color',[1 1 1]);
% hBar=bar(1:(length(roundvec))^3,bplotmatrix(sortindex,4)/expectedmatches,'hist');
% box off
% % set(gca,'XTickLabel',names,'XLim',[-0.5,10.5],'YLim',[0,.5]);
% ylabel('% of responses');
% set(hBar,'FaceVertexCData',bplotmatrix(sortindex,1:3));
%
%
end
% across all letters
% uniform matches at each point
expectedmatches = sum(allletterhists)/(length(roundvec))^3;
% for the bar plot we need to sort the bplotmatrix
[sorted sortindex] = sort(allletterhists);
% so for each letter
figure('name',['distribution across rgb space for ' dataname ' all letters'],'Color',[1 1 1]);
% trick for having bars and lines in the same plot is to have two axes
% but this yyaxis command is only in matlab 2016a
% yyaxis 'left
hBar=bar(1:(length(roundvec))^3,allletterhists(sortindex)/expectedmatches,'hist');
box off
% set(gca,'XTickLabel',names,'XLim',[-0.5,10.5],'YLim',[0,.5]);
ylabel('ratio of matches to uniform');
set(hBar,'FaceVertexCData',bplotmatrix(sortindex,1:3));
hold on;
set(gca,'XLim',[0.5 length(roundvec)^3+.5]);
% save current axis
a1 = gca;
% make a new one in exactly the same place
a2 = axes('Position',get(a1,'Position'));
% this should add a dashed line at 1 meaning chosen proportionally to
% area of space (or area, diam, or whatever is 1)
plot(0:.5:length(roundvec)^3,1,'k-');
hold on;
% make second axis invixible
set(a2,'YAxisLocation','right','Color','none','XTickLabel',[])
% Align the x-axis of both axes and display the grid lines on top of the bars.
set(a2,'XLim',get(a1,'XLim'),'Layer','top')
% le