comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_stats_plot.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function som_stats_plot(csS,plottype,varargin)
2
3 %SOM_STATS_PLOT Plots of data set statistics.
4 %
5 % som_stats_plot(csS, plottype, [argID, value, ...])
6 %
7 % som_stats_plot(csS,'stats')
8 % som_stats_plot(csS,'stats','p','vert','color','r')
9 %
10 % Input and output arguments ([]'s are optional):
11 % csS (cell array) of statistics structs
12 % (struct) a statistics struct
13 % plottype (string) some of the following
14 % 'hist' histogram
15 % 'box' min, max, mean, and std shown as a boxplot
16 % 'stats' both histogram (with black) and the boxplot
17 % [argID, (string) See below. The values which are unambiguous can
18 % value] (varies) be given without the preceeding argID.
19 %
20 % Here are the valid argument IDs and corresponding values. The values which
21 % are unambiguous (marked with '*') can be given without the preceeding argID.
22 % 'counts' *(string) 'c' (for counts, the default) or 'p' (for percentages)
23 % 'color' (vector) size 1 x 3, color to be used
24 % (string) a color string
25 % 'title' (string) 'on' (default) or 'off'
26 % 'orientation' *(string) 'horiz' or 'vert' (default): orientation for the
27 % bin values (horizontally or vertically)
28 %
29 % See also SOM_STATS, SOM_STATS_TABLE, SOM_TABLE_PRINT, SOM_STATS_REPORT.
30
31 % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto
32 % Copyright (c) by Juha Vesanto
33 % http://www.cis.hut.fi/projects/somtoolbox/
34
35 % Version 2.0beta juuso 311201
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %% arguments
39
40 % statistics
41 if isstruct(csS), csS = {csS}; end
42
43 % default values
44 useprob = 0;
45 color = [0 0 1];
46 showtitle = 1;
47 horiz = 0;
48
49 % varargin
50 i=1;
51 while i<=length(varargin),
52 argok = 1;
53 if ischar(varargin{i}),
54 switch varargin{i},
55 % argument IDs
56 case 'counts', i=i+1; useprob = strcmp(varargin{i}(1),'p');
57 case 'color', i=i+1; color = varargin{i};
58 case 'title', i=i+1; showtitle = strcmp(varargin{i},'on');
59 case 'orientation', i=i+1; horiz = strcmp(varargin{i},'horiz');
60 % unambiguous values
61 case {'horiz','vert'}, horiz = strcmp(varargin{i},'horiz');
62 case {'c','p'}, useprob = strcmp(varargin{i}(1),'p');
63 otherwise argok=0;
64 end
65 elseif isstruct(varargin{i}) & isfield(varargin{i},'type'),
66 argok = 0;
67 else
68 argok = 0;
69 end
70 if ~argok,
71 disp(['(som_stats_plot) Ignoring invalid argument #' num2str(i+2)]);
72 end
73 i = i+1;
74 end
75
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
77 %% action
78
79 ss = ceil(sqrt(length(csS))); ss = [ss, ceil(length(csS)/ss)];
80
81 for j = 1:length(csS),
82 sS = csS{j};
83 subplot(ss(1),ss(2),j);
84 switch plottype,
85 case 'stats',
86 cla, hold on
87 Counts = sS.hist.counts;
88 if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end
89 hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color);
90 box_plot(sS.min,sS.max,sS.mean,sS.std,[0 0 0]);
91 case 'hist',
92 cla, hold on
93 Counts = sS.hist.counts;
94 if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end
95 hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color);
96 case 'box',
97 cla
98 box_plot(sS.min,sS.max,sS.mean,sS.std,color);
99 end
100 if showtitle, title(sprintf('%s (valid: %d/%d)',sS.name,sS.nvalid,sS.ntotal)); end
101 if ~horiz, view(90,-90); end
102 a = axis; a(1) = sS.min; a(2) = sS.max; axis(a);
103 end
104
105 return;
106
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
108 %% subfunctions
109
110 function hist_plot(bins,binlabels,Counts,color)
111
112 if nargin<4, color = jet(size(Counts,2)); end
113 h = bar(bins,Counts);
114 for j=1:length(h), set(h(j),'facecolor',color(j,:),'edgecolor','none'); end
115 a = axis; a(3:4) = [0 max(Counts(:))]; axis(a);
116 set(gca,'XTick',bins,'XTickLabel',binlabels);
117 return;
118
119 function vstr = numtostring(v,d)
120
121 nearzero = (abs(v)/(max(v)-min(v)) < 10.^-d);
122 i1 = find(v > 0 & nearzero);
123 i2 = find(v < 0 & nearzero);
124 vstr = strrep(cellstr(num2str(v,d)),' ','');
125 vstr(i1) = {'0.0'};
126 vstr(i2) = {'-0.0'};
127 return;
128
129 function box_plot(mi,ma,me,st,Color)
130
131 if nargin < 5, Color = jet(length(mi)); end
132 a = axis;
133 y = linspace(a(3),a(4),length(mi)+2); y = y(2:end);
134 d = (y(2)-y(1))/20;
135 for i=1:length(mi),
136 h1 = line([mi(i) ma(i)],[y(i) y(i)]);
137 h2 = line([mi(i) mi(i) NaN ma(i) ma(i)],[y(i)-d y(i)+d NaN y(i)-d y(i)+d]);
138 h3 = line([me(i)-st(i) me(i)+st(i)],[y(i) y(i)]);
139 h4 = line([me(i) me(i)],[y(i)-2*d y(i)+2*d]);
140 set([h1 h2 h3 h4],'color',Color(i,:));
141 set([h1 h2],'linewidth',1);
142 set([h3 h4],'linewidth',3);
143 end
144 return;