Daniel@0: function som_stats_plot(csS,plottype,varargin) Daniel@0: Daniel@0: %SOM_STATS_PLOT Plots of data set statistics. Daniel@0: % Daniel@0: % som_stats_plot(csS, plottype, [argID, value, ...]) Daniel@0: % Daniel@0: % som_stats_plot(csS,'stats') Daniel@0: % som_stats_plot(csS,'stats','p','vert','color','r') Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % csS (cell array) of statistics structs Daniel@0: % (struct) a statistics struct Daniel@0: % plottype (string) some of the following Daniel@0: % 'hist' histogram Daniel@0: % 'box' min, max, mean, and std shown as a boxplot Daniel@0: % 'stats' both histogram (with black) and the boxplot Daniel@0: % [argID, (string) See below. The values which are unambiguous can Daniel@0: % value] (varies) be given without the preceeding argID. Daniel@0: % Daniel@0: % Here are the valid argument IDs and corresponding values. The values which Daniel@0: % are unambiguous (marked with '*') can be given without the preceeding argID. Daniel@0: % 'counts' *(string) 'c' (for counts, the default) or 'p' (for percentages) Daniel@0: % 'color' (vector) size 1 x 3, color to be used Daniel@0: % (string) a color string Daniel@0: % 'title' (string) 'on' (default) or 'off' Daniel@0: % 'orientation' *(string) 'horiz' or 'vert' (default): orientation for the Daniel@0: % bin values (horizontally or vertically) Daniel@0: % Daniel@0: % See also SOM_STATS, SOM_STATS_TABLE, SOM_TABLE_PRINT, SOM_STATS_REPORT. Daniel@0: Daniel@0: % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto Daniel@0: % Copyright (c) by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 311201 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% arguments Daniel@0: Daniel@0: % statistics Daniel@0: if isstruct(csS), csS = {csS}; end Daniel@0: Daniel@0: % default values Daniel@0: useprob = 0; Daniel@0: color = [0 0 1]; Daniel@0: showtitle = 1; Daniel@0: horiz = 0; Daniel@0: Daniel@0: % varargin Daniel@0: i=1; Daniel@0: while i<=length(varargin), Daniel@0: argok = 1; Daniel@0: if ischar(varargin{i}), Daniel@0: switch varargin{i}, Daniel@0: % argument IDs Daniel@0: case 'counts', i=i+1; useprob = strcmp(varargin{i}(1),'p'); Daniel@0: case 'color', i=i+1; color = varargin{i}; Daniel@0: case 'title', i=i+1; showtitle = strcmp(varargin{i},'on'); Daniel@0: case 'orientation', i=i+1; horiz = strcmp(varargin{i},'horiz'); Daniel@0: % unambiguous values Daniel@0: case {'horiz','vert'}, horiz = strcmp(varargin{i},'horiz'); Daniel@0: case {'c','p'}, useprob = strcmp(varargin{i}(1),'p'); Daniel@0: otherwise argok=0; Daniel@0: end Daniel@0: elseif isstruct(varargin{i}) & isfield(varargin{i},'type'), Daniel@0: argok = 0; Daniel@0: else Daniel@0: argok = 0; Daniel@0: end Daniel@0: if ~argok, Daniel@0: disp(['(som_stats_plot) Ignoring invalid argument #' num2str(i+2)]); Daniel@0: end Daniel@0: i = i+1; Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 Daniel@0: %% action Daniel@0: Daniel@0: ss = ceil(sqrt(length(csS))); ss = [ss, ceil(length(csS)/ss)]; Daniel@0: Daniel@0: for j = 1:length(csS), Daniel@0: sS = csS{j}; Daniel@0: subplot(ss(1),ss(2),j); Daniel@0: switch plottype, Daniel@0: case 'stats', Daniel@0: cla, hold on Daniel@0: Counts = sS.hist.counts; Daniel@0: if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end Daniel@0: hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color); Daniel@0: box_plot(sS.min,sS.max,sS.mean,sS.std,[0 0 0]); Daniel@0: case 'hist', Daniel@0: cla, hold on Daniel@0: Counts = sS.hist.counts; Daniel@0: if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end Daniel@0: hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color); Daniel@0: case 'box', Daniel@0: cla Daniel@0: box_plot(sS.min,sS.max,sS.mean,sS.std,color); Daniel@0: end Daniel@0: if showtitle, title(sprintf('%s (valid: %d/%d)',sS.name,sS.nvalid,sS.ntotal)); end Daniel@0: if ~horiz, view(90,-90); end Daniel@0: a = axis; a(1) = sS.min; a(2) = sS.max; axis(a); Daniel@0: end Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 Daniel@0: %% subfunctions Daniel@0: Daniel@0: function hist_plot(bins,binlabels,Counts,color) Daniel@0: Daniel@0: if nargin<4, color = jet(size(Counts,2)); end Daniel@0: h = bar(bins,Counts); Daniel@0: for j=1:length(h), set(h(j),'facecolor',color(j,:),'edgecolor','none'); end Daniel@0: a = axis; a(3:4) = [0 max(Counts(:))]; axis(a); Daniel@0: set(gca,'XTick',bins,'XTickLabel',binlabels); Daniel@0: return; Daniel@0: Daniel@0: function vstr = numtostring(v,d) Daniel@0: Daniel@0: nearzero = (abs(v)/(max(v)-min(v)) < 10.^-d); Daniel@0: i1 = find(v > 0 & nearzero); Daniel@0: i2 = find(v < 0 & nearzero); Daniel@0: vstr = strrep(cellstr(num2str(v,d)),' ',''); Daniel@0: vstr(i1) = {'0.0'}; Daniel@0: vstr(i2) = {'-0.0'}; Daniel@0: return; Daniel@0: Daniel@0: function box_plot(mi,ma,me,st,Color) Daniel@0: Daniel@0: if nargin < 5, Color = jet(length(mi)); end Daniel@0: a = axis; Daniel@0: y = linspace(a(3),a(4),length(mi)+2); y = y(2:end); Daniel@0: d = (y(2)-y(1))/20; Daniel@0: for i=1:length(mi), Daniel@0: h1 = line([mi(i) ma(i)],[y(i) y(i)]); Daniel@0: h2 = line([mi(i) mi(i) NaN ma(i) ma(i)],[y(i)-d y(i)+d NaN y(i)-d y(i)+d]); Daniel@0: h3 = line([me(i)-st(i) me(i)+st(i)],[y(i) y(i)]); Daniel@0: h4 = line([me(i) me(i)],[y(i)-2*d y(i)+2*d]); Daniel@0: set([h1 h2 h3 h4],'color',Color(i,:)); Daniel@0: set([h1 h2],'linewidth',1); Daniel@0: set([h3 h4],'linewidth',3); Daniel@0: end Daniel@0: return;