File thirdparty/bplot.m changed (mode: 100644) (index 2963e4d..0c40ff5) |
83 |
83 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
84 |
84 |
%% |
%% |
85 |
85 |
function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) |
function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) |
86 |
|
%% save the initial hold state of the figure. |
|
87 |
|
hold_state = ishold; |
|
88 |
|
if ~hold_state |
|
89 |
|
cla; |
|
90 |
|
end |
|
91 |
|
%% |
|
92 |
|
if size(x,1)>1 && size(x,2)>1 % great, you want to plot a bunch. |
|
93 |
|
if isempty(varargin) |
|
94 |
|
forLegend = bplot(x(:,1),1); |
|
95 |
|
for ii=2:size(x,2) |
|
96 |
|
hold on; |
|
97 |
|
bplot(x(:,ii),ii,'nolegend'); |
|
|
86 |
|
%% save the initial hold state of the figure. |
|
87 |
|
hold_state = ishold; |
|
88 |
|
if ~hold_state |
|
89 |
|
cla; |
|
90 |
|
end |
|
91 |
|
%% |
|
92 |
|
if size(x,1)>1 && size(x,2)>1 % great, you want to plot a bunch. |
|
93 |
|
if isempty(varargin) |
|
94 |
|
forLegend = bplot(x(:,1),1); |
|
95 |
|
for ii=2:size(x,2) |
|
96 |
|
hold on; |
|
97 |
|
bplot(x(:,ii),ii,'nolegend'); |
|
98 |
|
end |
|
99 |
|
else |
|
100 |
|
if ~ischar(varargin{1}) |
|
101 |
|
warning('You can''t specify a location for multiple guys, this will probably crash'); |
|
102 |
|
end |
|
103 |
|
forLegend = bplot(x(:,1),1,varargin{:}); |
|
104 |
|
for ii=2:size(x,2) |
|
105 |
|
hold on; |
|
106 |
|
bplot(x(:,ii),ii,'nolegend',varargin{:}); |
|
107 |
|
|
|
108 |
|
end |
98 |
109 |
end |
end |
99 |
|
else |
|
100 |
|
if ~ischar(varargin{1}) |
|
101 |
|
warning('You can''t specify a location for multiple guys, this will probably crash'); |
|
|
110 |
|
if ~hold_state |
|
111 |
|
hold off; |
102 |
112 |
end |
end |
103 |
|
forLegend = bplot(x(:,1),1,varargin{:}); |
|
104 |
|
for ii=2:size(x,2) |
|
105 |
|
hold on; |
|
106 |
|
bplot(x(:,ii),ii,'nolegend',varargin{:}); |
|
|
113 |
|
return; |
|
114 |
|
end |
107 |
115 |
|
|
|
116 |
|
%% |
|
117 |
|
if ~isempty(varargin) |
|
118 |
|
if ischar(varargin{1}) |
|
119 |
|
justOneInputFlag=1; |
|
120 |
|
y=1; |
|
121 |
|
else |
|
122 |
|
justOneInputFlag=0; |
|
123 |
|
y=varargin{1}; |
108 |
124 |
end |
end |
|
125 |
|
else % not text arguments, not even separate 'x' argument |
|
126 |
|
y=1; |
|
127 |
|
justOneInputFlag=1; |
109 |
128 |
end |
end |
110 |
|
if ~hold_state |
|
111 |
|
hold off; |
|
112 |
|
end |
|
113 |
|
return; |
|
114 |
|
end |
|
115 |
129 |
|
|
116 |
|
%% |
|
117 |
|
if ~isempty(varargin) |
|
118 |
|
if ischar(varargin{1}) |
|
119 |
|
justOneInputFlag=1; |
|
|
130 |
|
%% check that there is at least some data |
|
131 |
|
if isempty(x) |
|
132 |
|
warning('you asked for no data, so no data is what you plot.'); |
|
133 |
|
forLegend = ''; |
|
134 |
|
return; |
|
135 |
|
end |
|
136 |
|
%% |
|
137 |
|
if length(y)>1 |
|
138 |
|
warning('The location can only be a scalar, it has been set to ''1'''); |
120 |
139 |
y=1; |
y=1; |
121 |
|
else |
|
122 |
|
justOneInputFlag=0; |
|
123 |
|
y=varargin{1}; |
|
124 |
140 |
end |
end |
125 |
|
else % not text arguments, not even separate 'x' argument |
|
126 |
|
y=1; |
|
127 |
|
justOneInputFlag=1; |
|
128 |
|
end |
|
129 |
141 |
|
|
130 |
|
%% check that there is at least some data |
|
131 |
|
if isempty(x) |
|
132 |
|
warning('you asked for no data, so no data is what you plot.'); |
|
133 |
|
forLegend = ''; |
|
134 |
|
return; |
|
135 |
|
end |
|
136 |
|
%% |
|
137 |
|
if length(y)>1 |
|
138 |
|
warning('The location can only be a scalar, it has been set to ''1'''); |
|
139 |
|
y=1; |
|
140 |
|
end |
|
141 |
|
|
|
142 |
|
%% serialize and remove NaNs |
|
143 |
|
x=x(:); |
|
144 |
|
x = x(~isnan(x)); |
|
|
142 |
|
%% serialize and remove NaNs |
|
143 |
|
x=x(:); |
|
144 |
|
x = x(~isnan(x)); |
145 |
145 |
|
|
146 |
|
%% Initialize some things before accepting user parameters |
|
147 |
|
horizontalFlag=0; |
|
148 |
|
barFactor=1; % |
|
149 |
|
linewidth=2; |
|
150 |
|
forceNoLegend=0; % will any legend items be allowed in. |
|
151 |
|
stdFlag = 0; |
|
152 |
|
meanFlag = 1; |
|
153 |
|
specialWidthFlag = 0; % this flag will determine whether the bar width is |
|
154 |
|
% automatically set as a proportion of the axis width |
|
|
146 |
|
%% Initialize some things before accepting user parameters |
|
147 |
|
horizontalFlag=0; |
|
148 |
|
barFactor=1; % |
|
149 |
|
linewidth=2; |
|
150 |
|
forceNoLegend=0; % will any legend items be allowed in. |
|
151 |
|
stdFlag = 0; |
|
152 |
|
meanFlag = 1; |
|
153 |
|
specialWidthFlag = 0; % this flag will determine whether the bar width is |
|
154 |
|
% automatically set as a proportion of the axis width |
155 |
155 |
|
|
156 |
|
toScale = 0; % this flag is to scale the jitter function in case the |
|
157 |
|
% histogram function is calling it |
|
|
156 |
|
toScale = 0; % this flag is to scale the jitter function in case the |
|
157 |
|
% histogram function is calling it |
158 |
158 |
|
|
159 |
|
if justOneInputFlag |
|
160 |
|
if length(x)<400 |
|
161 |
|
outlierFlag = 1; |
|
|
159 |
|
if justOneInputFlag |
|
160 |
|
if length(x)<400 |
|
161 |
|
outlierFlag = 1; |
|
162 |
|
else |
|
163 |
|
outlierFlag = 0; |
|
164 |
|
end |
162 |
165 |
else |
else |
163 |
166 |
outlierFlag = 0; |
outlierFlag = 0; |
164 |
167 |
end |
end |
165 |
|
|
|
166 |
|
else |
|
167 |
|
outlierFlag = 0; |
|
168 |
|
end |
|
169 |
|
widthFlag =0; |
|
|
168 |
|
widthFlag =0; |
170 |
169 |
|
|
171 |
|
boxColor = [0.0005 0.3593 0.7380]; |
|
172 |
|
wisColor = [0 0 0]+.3; |
|
173 |
|
meanColor = [0.9684 0.2799 0.0723]; |
|
|
170 |
|
boxColor = [0.0005 0.3593 0.7380]; |
|
171 |
|
wisColor = [0 0 0]+.3; |
|
172 |
|
meanColor = [0.9684 0.2799 0.0723]; |
174 |
173 |
|
|
175 |
|
percentileNum = 25; % for the main quantiles |
|
176 |
|
percentileNum2 = 9; % for the whisker ends |
|
|
174 |
|
percentileNum = 25; % for the main quantiles |
|
175 |
|
percentileNum2 = 9; % for the whisker ends |
177 |
176 |
|
|
178 |
|
%% interpret user paramters |
|
179 |
|
k = 1 + 1 - justOneInputFlag; |
|
180 |
|
while k <= length(varargin) |
|
181 |
|
if ischar(varargin{k}) |
|
182 |
|
switch (lower(varargin{k})) |
|
183 |
|
case 'nolegend' |
|
184 |
|
forceNoLegend=1; |
|
185 |
|
case {'box','boxes','boxedge'} |
|
186 |
|
percentileNum = varargin{k + 1}; |
|
187 |
|
k = k + 1; |
|
188 |
|
case {'wisker','wiskers','whisker','whiskers','whiskeredge'} |
|
189 |
|
percentileNum2 = varargin{k + 1}; |
|
190 |
|
k = k + 1; |
|
191 |
|
case {'std','standard'} |
|
192 |
|
stdFlag = 1; |
|
193 |
|
case 'linewidth' |
|
194 |
|
linewidth = varargin{k + 1}; |
|
195 |
|
k = k + 1; |
|
196 |
|
case {'color','colors'} |
|
197 |
|
boxColor = varargin{k+1}; |
|
198 |
|
wisColor = varargin{k+1}; |
|
199 |
|
meanColor = varargin{k+1}; |
|
200 |
|
forceNoLegend=1; |
|
201 |
|
k = k + 1; |
|
202 |
|
case {'points','dots','outliers'} % display those outliers |
|
203 |
|
outlierFlag = 1; |
|
204 |
|
case {'nopoints','nodots','nooutliers'} % display those outliers |
|
205 |
|
outlierFlag = 0; |
|
206 |
|
case {'horizontal','horiz'} |
|
207 |
|
horizontalFlag = 1; |
|
208 |
|
% case {'serror','serrors','stderror','stderrors','sem'} |
|
209 |
|
% serrorFlag = 1; |
|
210 |
|
case {'width','barwidth'} |
|
211 |
|
barWidth = varargin{k+1}; |
|
212 |
|
widthFlag = 1; |
|
213 |
|
k = k+1; |
|
214 |
|
case {'specialwidth','proportionalwidth','width2'} |
|
215 |
|
specialWidthFlag = 1; |
|
216 |
|
widthFlag = 1; |
|
217 |
|
case {'nomean'} |
|
218 |
|
meanFlag=0; |
|
219 |
|
case {'toscale','histmode','hist'} |
|
220 |
|
toScale = 1; % scale away folks! |
|
221 |
|
|
|
222 |
|
% case {'mode','modes'} |
|
223 |
|
% modeFlag = 1; |
|
224 |
|
% case {'text','alltext','t'} % ????? |
|
225 |
|
% textFlag=1; |
|
226 |
|
otherwise |
|
227 |
|
warning('user entered parameter is not recognized') |
|
228 |
|
disp('unrecognized term is:'); disp(varargin{k}); |
|
229 |
|
end |
|
|
177 |
|
%% interpret user paramters |
|
178 |
|
k = 1 + 1 - justOneInputFlag; |
|
179 |
|
while k <= length(varargin) |
|
180 |
|
if ischar(varargin{k}) |
|
181 |
|
switch (lower(varargin{k})) |
|
182 |
|
case 'nolegend' |
|
183 |
|
forceNoLegend=1; |
|
184 |
|
case {'box','boxes','boxedge'} |
|
185 |
|
percentileNum = varargin{k + 1}; |
|
186 |
|
k = k + 1; |
|
187 |
|
case {'wisker','wiskers','whisker','whiskers','whiskeredge'} |
|
188 |
|
percentileNum2 = varargin{k + 1}; |
|
189 |
|
k = k + 1; |
|
190 |
|
case {'std','standard'} |
|
191 |
|
stdFlag = 1; |
|
192 |
|
case 'linewidth' |
|
193 |
|
linewidth = varargin{k + 1}; |
|
194 |
|
k = k + 1; |
|
195 |
|
case {'color','colors'} |
|
196 |
|
boxColor = varargin{k+1}; |
|
197 |
|
wisColor = varargin{k+1}; |
|
198 |
|
meanColor = varargin{k+1}; |
|
199 |
|
forceNoLegend=1; |
|
200 |
|
k = k + 1; |
|
201 |
|
case {'points','dots','outliers'} % display those outliers |
|
202 |
|
outlierFlag = 1; |
|
203 |
|
case {'nopoints','nodots','nooutliers'} % display those outliers |
|
204 |
|
outlierFlag = 0; |
|
205 |
|
case {'horizontal','horiz'} |
|
206 |
|
horizontalFlag = 1; |
|
207 |
|
case {'width','barwidth'} |
|
208 |
|
barWidth = varargin{k+1}; |
|
209 |
|
widthFlag = 1; |
|
210 |
|
k = k+1; |
|
211 |
|
case {'specialwidth','proportionalwidth','width2'} |
|
212 |
|
specialWidthFlag = 1; |
|
213 |
|
widthFlag = 1; |
|
214 |
|
case {'nomean'} |
|
215 |
|
meanFlag=0; |
|
216 |
|
case {'toscale','histmode','hist'} |
|
217 |
|
toScale = 1; % scale away folks! |
|
218 |
|
otherwise |
|
219 |
|
warning('user entered parameter is not recognized') |
|
220 |
|
disp('unrecognized term is:'); disp(varargin{k}); |
|
221 |
|
end |
|
222 |
|
end |
|
223 |
|
k = k + 1; |
230 |
224 |
end |
end |
231 |
|
k = k + 1; |
|
232 |
|
end |
|
233 |
225 |
|
|
234 |
|
%% |
|
235 |
|
meanX = mean(x); |
|
236 |
|
medianX = median(x); |
|
237 |
|
defaultBarFactor=1.5/20; |
|
238 |
|
p=axis; |
|
239 |
|
if ~widthFlag % if the user didn't specify a specific width of the bar. |
|
240 |
|
if specialWidthFlag |
|
241 |
|
barWidth=barFactor*(p(4)-p(3))*defaultBarFactor; |
|
|
226 |
|
%% |
|
227 |
|
meanX = mean(x); |
|
228 |
|
medianX = median(x); |
|
229 |
|
defaultBarFactor=1.5/20; |
|
230 |
|
p=axis; |
|
231 |
|
if ~widthFlag % if the user didn't specify a specific width of the bar. |
|
232 |
|
if specialWidthFlag |
|
233 |
|
barWidth=barFactor*(p(4)-p(3))*defaultBarFactor; |
|
234 |
|
else |
|
235 |
|
barWidth = .8; |
|
236 |
|
% barWidth = barFactor*(p(2)-p(1))*defaultBarFactor/5; |
|
237 |
|
end |
|
238 |
|
end |
|
239 |
|
%% calculate the necessary values for the sizes of the box and whiskers |
|
240 |
|
boxEdge = prctile(x,[percentileNum 100-percentileNum]); |
|
241 |
|
IQR=max(diff(boxEdge),eps); % in case IQR is zero, make it eps |
|
242 |
|
if stdFlag |
|
243 |
|
stdX = std(x); |
|
244 |
|
wisEdge = [meanX-stdX meanX+stdX]; |
242 |
245 |
else |
else |
243 |
|
barWidth = .8; |
|
244 |
|
% barWidth = barFactor*(p(2)-p(1))*defaultBarFactor/5; |
|
|
246 |
|
wisEdge = prctile(x,[percentileNum2 100-percentileNum2]); |
245 |
247 |
end |
end |
246 |
|
end |
|
247 |
|
%% calculate the necessary values for the sizes of the box and whiskers |
|
248 |
|
boxEdge = prctile(x,[percentileNum 100-percentileNum]); |
|
249 |
|
IQR=max(diff(boxEdge),eps); % in case IQR is zero, make it eps |
|
250 |
|
if stdFlag |
|
251 |
|
stdX = std(x); |
|
252 |
|
wisEdge = [meanX-stdX meanX+stdX]; |
|
253 |
|
else |
|
254 |
|
wisEdge = prctile(x,[percentileNum2 100-percentileNum2]); |
|
255 |
|
end |
|
256 |
|
|
|
257 |
|
%% display all the elements for the box plot |
|
258 |
248 |
|
|
259 |
|
hReg=[]; |
|
260 |
|
hReg2 = []; |
|
|
249 |
|
%% display all the elements for the box plot |
261 |
250 |
|
|
262 |
|
if horizontalFlag |
|
263 |
|
hReg2(end+1) = rectangle('Position',[boxEdge(1),y-barWidth/2,IQR,barWidth],'linewidth',linewidth,'EdgeColor',boxColor,'facecolor',[1 1 1]); |
|
|
251 |
|
hReg = []; |
|
252 |
|
hReg2 = []; |
264 |
253 |
|
|
265 |
|
hold on; |
|
266 |
|
hReg2(end+1) = plot([medianX medianX],[y-barWidth/2 y+barWidth/2],'color',meanColor,'linewidth',linewidth); |
|
267 |
|
if meanFlag |
|
268 |
|
hReg2(end+1) = plot(meanX,y,'+','color',meanColor,'linewidth',linewidth,'markersize',10); |
|
269 |
|
end |
|
270 |
|
hReg2(end+1) = plot([boxEdge(1) boxEdge(2)],[y-barWidth/2 y-barWidth/2],'linewidth',linewidth,'color',boxColor); |
|
|
254 |
|
if horizontalFlag |
|
255 |
|
hReg2(end+1) = rectangle('Position',[boxEdge(1),y-barWidth/2,IQR,barWidth],'linewidth',linewidth,... |
|
256 |
|
'EdgeColor',boxColor, 'facecolor',[1 1 1]); |
271 |
257 |
|
|
272 |
|
hReg(end+1) = plot([wisEdge(1) boxEdge(1)],[y y],'--','linewidth',linewidth,'color',wisColor); |
|
273 |
|
hReg(end+1) = plot([boxEdge(2) wisEdge(2)],[y y],'--','linewidth',linewidth,'color',wisColor); |
|
274 |
|
hReg2(end+1) = plot([wisEdge(1) wisEdge(1)],[y-barWidth/3 y+barWidth/3],'-','linewidth',linewidth,'color',wisColor); |
|
275 |
|
hReg(end+1) = plot([wisEdge(2) wisEdge(2)],[y-barWidth/3 y+barWidth/3],'-','linewidth',linewidth,'color',wisColor); |
|
276 |
|
else % |
|
277 |
|
hReg2(end+1) = rectangle('Position',[y-barWidth/2,boxEdge(1),barWidth,IQR],'linewidth',linewidth,'EdgeColor',boxColor,'facecolor',[1 1 1]); |
|
278 |
|
hold on; |
|
279 |
|
|
|
280 |
|
hReg2(end+1) = plot([y-barWidth/2 y+barWidth/2],[medianX medianX],'color',meanColor,'linewidth',linewidth); |
|
281 |
|
if meanFlag |
|
282 |
|
hReg2(end+1) = plot(y,meanX,'+','linewidth',linewidth,'color',meanColor,'markersize',10); |
|
283 |
|
end |
|
284 |
|
hReg2(end+1) = plot([y-barWidth/2 y-barWidth/2],[boxEdge(1) boxEdge(2)],'linewidth',linewidth,'color',boxColor); |
|
|
258 |
|
hold on; |
|
259 |
|
hReg2(end+1) = plot([medianX medianX],[y-barWidth/2 y+barWidth/2],'color',meanColor,'linewidth',linewidth); |
|
260 |
|
if meanFlag |
|
261 |
|
hReg2(end+1) = plot(meanX,y,'+','color',meanColor,'linewidth',linewidth,'markersize',10); |
|
262 |
|
end |
|
263 |
|
hReg2(end+1) = plot([boxEdge(1) boxEdge(2)],[y-barWidth/2 y-barWidth/2],'linewidth',linewidth,'color',boxColor); |
285 |
264 |
|
|
286 |
|
hReg(end+1) = plot([y y],[wisEdge(1) boxEdge(1)],'--','linewidth',linewidth,'color',wisColor); |
|
287 |
|
hReg(end+1) = plot([y y],[boxEdge(2) wisEdge(2)],'--','linewidth',linewidth,'color',wisColor); |
|
288 |
|
hReg2(end+1) = plot([y-barWidth/3 y+barWidth/3],[wisEdge(1) wisEdge(1)],'-','linewidth',linewidth,'color',wisColor); |
|
289 |
|
hReg(end+1) = plot([y-barWidth/3 y+barWidth/3],[wisEdge(2) wisEdge(2)],'-','linewidth',linewidth,'color',wisColor); |
|
|
265 |
|
hReg(end+1) = plot([wisEdge(1) boxEdge(1)],[y y],'--','linewidth',linewidth,'color',wisColor); |
|
266 |
|
hReg(end+1) = plot([boxEdge(2) wisEdge(2)],[y y],'--','linewidth',linewidth,'color',wisColor); |
|
267 |
|
hReg2(end+1) = plot([wisEdge(1) wisEdge(1)],[y-barWidth/3 y+barWidth/3],'-','linewidth',linewidth,'color',wisColor); |
|
268 |
|
hReg(end+1) = plot([wisEdge(2) wisEdge(2)],[y-barWidth/3 y+barWidth/3],'-','linewidth',linewidth,'color',wisColor); |
|
269 |
|
else % |
|
270 |
|
hReg2(end+1) = rectangle('Position',[y-barWidth/2,boxEdge(1),barWidth,IQR],'linewidth',linewidth,... |
|
271 |
|
'EdgeColor',boxColor, 'facecolor',[1 1 1]); |
|
272 |
|
hold on; |
|
273 |
|
|
|
274 |
|
hReg2(end+1) = plot([y-barWidth/2 y+barWidth/2],[medianX medianX],'color',meanColor,'linewidth',linewidth); |
|
275 |
|
if meanFlag |
|
276 |
|
hReg2(end+1) = plot(y,meanX,'+','linewidth',linewidth,'color',meanColor,'markersize',10); |
|
277 |
|
end |
|
278 |
|
hReg2(end+1) = plot([y-barWidth/2 y-barWidth/2],[boxEdge(1) boxEdge(2)],'linewidth',linewidth,'color',boxColor); |
290 |
279 |
|
|
291 |
|
end |
|
|
280 |
|
hReg(end+1) = plot([y y],[wisEdge(1) boxEdge(1)],'--','linewidth',linewidth,'color',wisColor); |
|
281 |
|
hReg(end+1) = plot([y y],[boxEdge(2) wisEdge(2)],'--','linewidth',linewidth,'color',wisColor); |
|
282 |
|
hReg2(end+1) = plot([y-barWidth/3 y+barWidth/3],[wisEdge(1) wisEdge(1)],'-','linewidth',linewidth,'color',wisColor); |
|
283 |
|
hReg(end+1) = plot([y-barWidth/3 y+barWidth/3],[wisEdge(2) wisEdge(2)],'-','linewidth',linewidth,'color',wisColor); |
292 |
284 |
|
|
293 |
|
%% add the points to the graph |
|
294 |
|
% Note that the spread of points should depend on the width of the bars and |
|
295 |
|
% the total number of points that need to be spread. |
|
296 |
|
if outlierFlag % but only if you want to |
|
297 |
|
I = (x<wisEdge(1))+(x>wisEdge(2)); |
|
298 |
|
I=logical(I); |
|
299 |
|
xx=x(I); |
|
300 |
|
yy=I*0+y; |
|
301 |
|
yy=yy(I); |
|
302 |
|
yy = jitter(xx,yy,toScale); |
|
|
285 |
|
end |
303 |
286 |
|
|
304 |
|
if ~isempty(yy) |
|
|
287 |
|
%% add the points to the graph |
|
288 |
|
% Note that the spread of points should depend on the width of the bars and |
|
289 |
|
% the total number of points that need to be spread. |
|
290 |
|
if outlierFlag % but only if you want to |
|
291 |
|
I = (x<wisEdge(1))+(x>wisEdge(2)); |
|
292 |
|
I=logical(I); |
|
293 |
|
xx=x(I); |
|
294 |
|
yy=I*0+y; |
|
295 |
|
yy=yy(I); |
305 |
296 |
yy = jitter(xx,yy,toScale); |
yy = jitter(xx,yy,toScale); |
306 |
297 |
|
|
307 |
|
maxPointHeight = 2.5; |
|
308 |
|
yy = (yy-y)*4+y; |
|
309 |
|
yy = (yy-y)*(barWidth/maxPointHeight)/max([yy-y; barWidth/maxPointHeight])+y; |
|
|
298 |
|
if ~isempty(yy) |
|
299 |
|
yy = jitter(xx,yy,toScale); |
|
300 |
|
|
|
301 |
|
maxPointHeight = 2.5; |
|
302 |
|
yy = (yy-y)*4+y; |
|
303 |
|
yy = (yy-y)*(barWidth/maxPointHeight)/max([yy-y; barWidth/maxPointHeight])+y; |
310 |
304 |
|
|
311 |
|
if ~isempty(xx) |
|
312 |
|
if horizontalFlag |
|
313 |
|
hReg2(6) = plot(xx,yy,'o','linewidth',linewidth,'color',wisColor); |
|
314 |
|
else |
|
315 |
|
hReg2(6) = plot(yy,xx,'o','linewidth',linewidth,'color',wisColor); |
|
|
305 |
|
if ~isempty(xx) |
|
306 |
|
if horizontalFlag |
|
307 |
|
hReg2(6) = plot(xx,yy,'o','linewidth',linewidth,'color',wisColor); |
|
308 |
|
else |
|
309 |
|
hReg2(6) = plot(yy,xx,'o','linewidth',linewidth,'color',wisColor); |
|
310 |
|
end |
316 |
311 |
end |
end |
317 |
312 |
end |
end |
318 |
313 |
end |
end |
319 |
|
end |
|
320 |
|
%% Remove the legend entries |
|
321 |
|
% remove extras for all the items. |
|
322 |
|
for ii=1:length(hReg) |
|
323 |
|
set(get(get(hReg(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend |
|
324 |
|
end |
|
|
314 |
|
%% Remove the legend entries |
|
315 |
|
% remove extras for all the items. |
|
316 |
|
for ii=1:length(hReg) |
|
317 |
|
set(get(get(hReg(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend |
|
318 |
|
end |
325 |
319 |
|
|
326 |
|
% remove all remenants of legends |
|
327 |
|
if forceNoLegend |
|
328 |
|
for ii=1:length(hReg2) |
|
329 |
|
set(get(get(hReg2(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend |
|
|
320 |
|
% remove all remenants of legends |
|
321 |
|
if forceNoLegend |
|
322 |
|
for ii=1:length(hReg2) |
|
323 |
|
set(get(get(hReg2(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend |
|
324 |
|
end |
330 |
325 |
end |
end |
331 |
|
end |
|
332 |
|
%% set the axis |
|
333 |
|
% The axis is only messed with if you didn't pass a position value (because |
|
334 |
|
% I figured you just wanted to make a quick plot without worry about much |
|
|
326 |
|
%% set the axis |
|
327 |
|
% The axis is only messed with if you didn't pass a position value (because |
|
328 |
|
% I figured you just wanted to make a quick plot without worry about much |
335 |
329 |
|
|
336 |
|
if justOneInputFlag |
|
337 |
|
if horizontalFlag |
|
338 |
|
padxfac = .1; |
|
339 |
|
padyfac = 2; |
|
|
330 |
|
if justOneInputFlag |
|
331 |
|
if horizontalFlag |
|
332 |
|
padxfac = .1; |
|
333 |
|
padyfac = 2; |
|
334 |
|
else |
|
335 |
|
padxfac = 2; |
|
336 |
|
padyfac = .1; |
|
337 |
|
end |
|
338 |
|
|
|
339 |
|
axis tight; |
|
340 |
|
p = axis; |
|
341 |
|
padx = (p(2)-p(1))*padxfac; pady = (p(4)-p(3))*padyfac; |
|
342 |
|
axis(p+[-padx padx -pady pady]); |
|
343 |
|
end |
|
344 |
|
%% Set the legend |
|
345 |
|
if stdFlag |
|
346 |
|
whiskerText = '\mu � \sigma'; |
|
347 |
|
else |
|
348 |
|
whiskerText = [num2str(percentileNum2) '%-' num2str(100-percentileNum2) '%']; |
|
349 |
|
end |
|
350 |
|
if meanFlag |
|
351 |
|
forLegend={'Median','\mu',[num2str(percentileNum) '%-' num2str(100-percentileNum) '%'],whiskerText,'outliers'}; |
340 |
352 |
else |
else |
341 |
|
padxfac = 2; |
|
342 |
|
padyfac = .1; |
|
|
353 |
|
forLegend={'Median',[num2str(percentileNum) '%-' num2str(100-percentileNum) '%'],whiskerText,'outliers'}; |
343 |
354 |
end |
end |
344 |
|
|
|
345 |
|
axis tight; |
|
346 |
|
p = axis; |
|
347 |
|
padx = (p(2)-p(1))*padxfac; pady = (p(4)-p(3))*padyfac; |
|
348 |
|
axis(p+[-padx padx -pady pady]); |
|
349 |
|
end |
|
350 |
|
%% Set the legend |
|
351 |
|
if stdFlag |
|
352 |
|
whiskerText = '\mu � \sigma'; |
|
353 |
|
else |
|
354 |
|
whiskerText = [num2str(percentileNum2) '%-' num2str(100-percentileNum2) '%']; |
|
355 |
|
end |
|
356 |
|
if meanFlag |
|
357 |
|
forLegend={'Median','\mu',[num2str(percentileNum) '%-' num2str(100-percentileNum) '%'],whiskerText,'outliers'}; |
|
358 |
|
else |
|
359 |
|
forLegend={'Median',[num2str(percentileNum) '%-' num2str(100-percentileNum) '%'],whiskerText,'outliers'}; |
|
360 |
|
end |
|
361 |
355 |
|
|
362 |
|
%% return the hold state |
|
363 |
|
% just being polite and putting the hold state back to the way it was. |
|
364 |
|
if ~hold_state |
|
365 |
|
hold off; |
|
366 |
|
end |
|
367 |
|
% end main bplot function over |
|
|
356 |
|
%% return the hold state |
|
357 |
|
% just being polite and putting the hold state back to the way it was. |
|
358 |
|
if ~hold_state |
|
359 |
|
hold off; |
|
360 |
|
end |
|
361 |
|
% end main bplot function over |
368 |
362 |
|
|
369 |
363 |
%% jitter function |
%% jitter function |
370 |
364 |
% in case two point appear at the same value, the jitter function will make |
% in case two point appear at the same value, the jitter function will make |
371 |
365 |
% them appear slightly separated from each other so you can see the real |
% them appear slightly separated from each other so you can see the real |
372 |
366 |
% number of points at a given location. |
% number of points at a given location. |
373 |
367 |
function yy =jitter(xx,yy,toScale) |
function yy =jitter(xx,yy,toScale) |
374 |
|
if toScale |
|
375 |
|
tempY=yy(1); |
|
376 |
|
else |
|
377 |
|
tempY=1; |
|
378 |
|
end |
|
|
368 |
|
if toScale |
|
369 |
|
tempY=yy(1); |
|
370 |
|
else |
|
371 |
|
tempY=1; |
|
372 |
|
end |
379 |
373 |
|
|
380 |
|
for ii=unique(xx)'; |
|
381 |
|
I = xx==(ii); |
|
382 |
|
fI = find(I)'; |
|
383 |
|
push = -(length(fI)-1)/2; % so it will be centered if there is only one. |
|
384 |
|
for jj=fI |
|
385 |
|
yy(jj)=yy(jj)+tempY/50*(push); |
|
386 |
|
push = push+1; |
|
|
374 |
|
for ii=unique(xx)'; |
|
375 |
|
I = xx==(ii); |
|
376 |
|
fI = find(I)'; |
|
377 |
|
push = -(length(fI)-1)/2; % so it will be centered if there is only one. |
|
378 |
|
for jj=fI |
|
379 |
|
yy(jj)=yy(jj)+tempY/50*(push); |
|
380 |
|
push = push+1; |
|
381 |
|
end |
387 |
382 |
end |
end |
388 |
|
end |
|
389 |
383 |
|
|
390 |
384 |
%% This is the function for calculating the quantiles for the bplot. |
%% This is the function for calculating the quantiles for the bplot. |
391 |
385 |
function yi = prctile(X,p) |
function yi = prctile(X,p) |
392 |
|
x=X(:); |
|
393 |
|
if length(x)~=length(X) |
|
394 |
|
error('please pass a vector only'); |
|
395 |
|
end |
|
396 |
|
n = length(x); |
|
397 |
|
x = sort(x); |
|
398 |
|
Y = 100*(.5 :1:n-.5)/n; |
|
399 |
|
x=[min(x); x; max(x)]; |
|
400 |
|
Y = [0 Y 100]; |
|
401 |
|
yi = interp1(Y,x,p); |
|
|
386 |
|
x=X(:); |
|
387 |
|
if length(x)~=length(X) |
|
388 |
|
error('please pass a vector only'); |
|
389 |
|
end |
|
390 |
|
n = length(x); |
|
391 |
|
x = sort(x); |
|
392 |
|
Y = 100*(.5 :1:n-.5)/n; |
|
393 |
|
x=[min(x); x; max(x)]; |
|
394 |
|
Y = [0 Y 100]; |
|
395 |
|
yi = interp1(Y,x,p); |