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