wolffd@0: function h=som_show(sMap, varargin) wolffd@0: wolffd@0: % SOM_SHOW Basic SOM visualizations: component planes, u-matrix etc. wolffd@0: % wolffd@0: % h = som_show(sMap, ['argID', value, ...]) wolffd@0: % wolffd@0: % som_show(sMap); wolffd@0: % som_show(sMap,'bar','none'); wolffd@0: % som_show(sMap,'comp',[1:3],'umat','all'); wolffd@0: % som_show(sMap,'comp',[1 2],'umat',{[1 2],'1,2 only'},'comp',[3:6]); wolffd@0: % som_show(sMap,'size',m,'bar','vert','edge','off'); wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % sMap (struct) map struct wolffd@0: % [argID, (string) Additional parameters are given as argID, value wolffd@0: % value] (varies) pairs. See below for list of valid IDs and values. wolffd@0: % wolffd@0: % h (struct) struct with the following fields: wolffd@0: % .plane (vector) handles to the axes objecets (subplots) wolffd@0: % .colorbar (vector) handles to the colorbars. Colorbars for empty wolffd@0: % grids & RGB color planes do not exist: the wolffd@0: % value for them in the vector is -1. wolffd@0: % .label (vector) handles to the axis labels wolffd@0: % wolffd@0: % Here are the valid argument IDs and corresponding values. M is wolffd@0: % the number of map units wolffd@0: % 'comp' Which component planes to draw, title is wolffd@0: % the name of the component (from sMap.comp_names) wolffd@0: % (vector) a vector of component indices wolffd@0: % (string) 'all' (or '' or []) for all components wolffd@0: % 'compi' as 'comp' but uses interpolated shading wolffd@0: % 'umat' Show u-matrix calculated using specified wolffd@0: % components wolffd@0: % (vector) a vector of component indeces wolffd@0: % (string) 'all' (or '' or []) to use all components wolffd@0: % (cell) of form {v, str} uses v as the vector, and put wolffd@0: % str as title instead of the default 'U-matrix' wolffd@0: % 'umati' as 'umat' but uses interpolated shading of colors wolffd@0: % 'empty' (string) Make an empty plane using given string as title wolffd@0: % 'color' Set arbitrary unit colors explicitly wolffd@0: % (matrix) size Mx1 or Mx3, Mx1 matrix uses indexed wolffd@0: % coloring; Mx3 matrix (RGB triples as rows) wolffd@0: % defines fixed unit colors wolffd@0: % (cell) of from {color, str}. 'color' is the Mx1 wolffd@0: % or Mx3 RGB triple matrix and 'str' is title wolffd@0: % string wolffd@0: % 'colori' as 'color' but uses interpolated shading of colors wolffd@0: % 'norm' (string) 'n' or 'd': Whether to show normalized 'n' or wolffd@0: % denormalized 'd' data values on the wolffd@0: % colorbar. By default denormalized values are used. wolffd@0: % 'bar' (string) Colorbar direction: 'horiz', 'vert' (default) wolffd@0: % or 'none' wolffd@0: % 'size' size of the units wolffd@0: % (scalar) same size for each unit, default is 1 wolffd@0: % (vector) size Mx1, individual size for each unit wolffd@0: % 'edge' (string) Unit edges on component planes 'on' wolffd@0: % (default) or 'off' wolffd@0: % 'footnote' (string) Footnote string, sMap.name by default wolffd@0: % 'colormap' (matrix) user defined colormap wolffd@0: % 'subplots' (vector) size 1 x 2, the number of subplots in y- and wolffd@0: % and x-directions (as in SUBPLOT command) wolffd@0: % wolffd@0: % If identifiers 'comp', 'compi', 'umat', 'umati', 'color', 'colori' wolffd@0: % or 'empty' are not specified at all, e.g. som_show(sMap) or wolffd@0: % som_show(sMap,'bar','none'), the U-matrix and all component planes wolffd@0: % are shown. wolffd@0: % wolffd@0: % For more help, try 'type som_show' or check out online documentation. wolffd@0: % See also SOM_SHOW_ADD, SOM_SHOW_CLEAR, SOM_UMAT, SOM_CPLANE, SOM_GRID. wolffd@0: wolffd@0: %%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % wolffd@0: % som_show wolffd@0: % wolffd@0: % PURPOSE wolffd@0: % wolffd@0: % Shows basic visualizations of SOM: component planes, unified distance wolffd@0: % matrices as well as empty planes and fixed color planes. wolffd@0: % wolffd@0: % SYNTAX wolffd@0: % wolffd@0: % h = som_show(sMap) wolffd@0: % h = som_show(sMap, 'argID', value, ...) wolffd@0: % wolffd@0: % DESCRIPTION wolffd@0: % wolffd@0: % This function is used for basic visualization of the SOM. Four wolffd@0: % kinds of SOM planes can be shown: wolffd@0: % wolffd@0: % 1. U-matrix (see SOM_UMAT) which shows clustering structure of wolffd@0: % the SOM. Either all or just part of the components can wolffd@0: % be used in calculating the U-matrix. wolffd@0: % 2. component planes: each component plane shows the values of wolffd@0: % one variable in each map unit wolffd@0: % 3. an empty plane which may be used as a base for, e.g., hit wolffd@0: % histogram visualization or labeling (see SOM_SHOW_ADD) wolffd@0: % 4. a fixed or indexed color representation for showing color coding or wolffd@0: % clustering wolffd@0: % wolffd@0: % The component planes and u-matrices may have colorbars showing the wolffd@0: % scale for the variable. The scale shows by default the values that wolffd@0: % variables have in the map struct. It may be changed to show the wolffd@0: % original data values (estimated by SOM_DENORMALIZE). In this case a wolffd@0: % small 'd' appears below the colorbar. The orientation of these wolffd@0: % colorbars may be changed, or they can be removed. wolffd@0: % wolffd@0: % By default the u-matrix - calculated using all variables - and all wolffd@0: % component planes are shown. This is achieved by giving command wolffd@0: % som_show(sMap) without any further arguments wolffd@0: % wolffd@0: % REQUIRED INPUT ARGUMENTS wolffd@0: % wolffd@0: % sMap (struct) Map to be shown. If only this argument is wolffd@0: % specified, the function draws first the u-matrix wolffd@0: % calculated using all the variables followed by all wolffd@0: % the component planes. wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS wolffd@0: % wolffd@0: % (M is the number of map units) wolffd@0: % wolffd@0: % Optional arguments must be given as 'argID',value -pairs wolffd@0: % wolffd@0: % 'comp' Defines the variabels to be shown as component planes. wolffd@0: % (vector) 1xN or Nx1 vector with integer positive numbers ranging wolffd@0: % from 1 to the number of variables in the map codebook wolffd@0: % (dim). This vector determines the variables to be show wolffd@0: % as component planes and their order. Note that the same wolffd@0: % component plane (the same variable index) is allowed to wolffd@0: % occur several times. wolffd@0: % (string) 'all' or '' or []. This uses all variables, that is, it's wolffd@0: % the same that using value [1:dim] where dim is the wolffd@0: % number of variables in the codebook. wolffd@0: % wolffd@0: % 'compi' Same as 'comp' but uses a Gouraud shaded color plane wolffd@0: % (made using SOM_GRID function) instead of the cell-like wolffd@0: % visualization of 'comp' (made using SOM_CPLANE). Note wolffd@0: % that the color interpolation doesn't work strictly wolffd@0: % correctly on 'hexa' grid, as it uses rectangular grid wolffd@0: % (see SURF). wolffd@0: % wolffd@0: % 'umat' Show U-matrix: value defines the variables to be used wolffd@0: % for calculating a u-matrix. wolffd@0: % (vector) as in 'comps'. However, multiple occurences of the wolffd@0: % same variable (same variable index) are ignored. wolffd@0: % (string) 'all' or '' or []. This uses all variables, that is, wolffd@0: % is the same as using value [1:dim] where dim is the wolffd@0: % number of variables in the codebook. wolffd@0: % (cell) of form {v, str} where v is a valid index vector for 'umat' wolffd@0: % (see above) and str is a string that is used as a title wolffd@0: % for the u-matrix instead of the default title wolffd@0: % 'U-matrix'. This may be useful if several u-matrices wolffd@0: % are shown in the same figure. wolffd@0: % wolffd@0: % 'umati' Same as 'umat' but uses shaded color plane (see 'compi'). wolffd@0: % wolffd@0: % 'empty' Show an empty plane (patch edges only) wolffd@0: % (string) value is used as title wolffd@0: % wolffd@0: % 'color' Define fixed RGB colors for the map units wolffd@0: % (matrix) a Mx3 matrix of RGB triples as rows wolffd@0: % (vector) a Mx1 vector of any values: sets indexed coloring using wolffd@0: % the current colormap (as SURF does) wolffd@0: % (matrix) a Mx3xN matrix of RGB triples as rows. This gives N wolffd@0: % color planes. wolffd@0: % (matrix) a Mx1xN matrix of any values: sets indexed coloring using wolffd@0: % the current colormap (as SURF does). This gives N wolffd@0: % color planes. wolffd@0: % (cell) of form {rgb, str} where rgb is a Mx3 (xN) matrix of RGB wolffd@0: % triples as rows and str is a string that is used as wolffd@0: % title(s). wolffd@0: % (cell) of form {v, str} where v is a Mx1(xN) matrix of values wolffd@0: % and str is a string that is used as title(s). wolffd@0: % wolffd@0: % 'colori' Same as 'color' but uses shaded color plane (see 'compi'). wolffd@0: % wolffd@0: % 'norm' Defines whether to use normalized or denormalized wolffd@0: % values in the colorbar. If denormalized values are wolffd@0: % used, they are acquired from SOM_DENORMALIZE function wolffd@0: % using sMap.comp_norm field. wolffd@0: % (string) 'd' (default) for denormalized values and 'n' for wolffd@0: % normalized values. The corresponding letter appears wolffd@0: % below the colorbar. wolffd@0: % wolffd@0: % 'bar' Define the direction of the colorbars for component planes wolffd@0: % and U-matrices or turn them completely off. wolffd@0: % (string) 'vert' (default), 'horiz' or 'none'. 'vert' gives wolffd@0: % vertical and 'horiz' horizontal colorbars. 'none' wolffd@0: % shows no colorbars at all. wolffd@0: % wolffd@0: % 'size' Define sizes of the units. wolffd@0: % (scalar) all units have the same size (1 by default) wolffd@0: % (vector) size Mx1, each unit gets individual size scaling wolffd@0: % (as in SOM_CPLANE) wolffd@0: % wolffd@0: % 'edge' Unit edges on component plane visualizations. wolffd@0: % (string) 'on' or 'off' determines whether the unit edges on component wolffd@0: % planes ('comp') are shown or not. Default is 'off'. Note that wolffd@0: % U-matrix and color planes are _always_ drawn without edges. wolffd@0: % wolffd@0: % 'footnote' Text on the figure wolffd@0: % (string) is printed as a movable text object on the figure wolffd@0: % where it may be moved using mouse. Default value is the wolffd@0: % string in the sMap.name field. Note: value [] gives the wolffd@0: % string, but input value '' gives no footnote a all. wolffd@0: % See VIS_FOOTNOTE for more information on the text object wolffd@0: % and ways to change its font size. wolffd@0: % wolffd@0: % 'colormap' som_show ghages the colormap by default to a gray-level map wolffd@0: % (matrix) This argument is used to set some other colormap. wolffd@0: % wolffd@0: % 'subplots' the number of subplots in y- and x-directions, as in wolffd@0: % (vector) command SUBPLOT wolffd@0: % wolffd@0: % OUTPUT ARGUMENTS wolffd@0: % wolffd@0: % h (struct) wolffd@0: % .plane (vector) handles to the axes objects (subplots) wolffd@0: % .colorbar (vector) handles to the colorbars. Colorbars of empty wolffd@0: % & color planes do not exist: the corresponding wolffd@0: % value in the vector is -1 wolffd@0: % .label (vector) handles to the axis labels wolffd@0: % wolffd@0: % OBJECT TAGS wolffd@0: % wolffd@0: % The property field 'Tag' of the axis objects created by this function wolffd@0: % are set to contain string 'Cplane' if the axis contains component plane wolffd@0: % ('comp'), color plane ('color') or empty plane ('empty') and string wolffd@0: % 'Uplane' if it contains a u-matrix ('umat'). The tag is set to wolffd@0: % 'CplaneI' for planes created using 'compi' and 'colori', and wolffd@0: % 'UplaneI' for 'umati'. wolffd@0: % wolffd@0: % FEATURES wolffd@0: % wolffd@0: % Note that when interpolated shading is used in coloring ('compi' and wolffd@0: % 'colori') the standard built-in bilinear Gouraud interpolation for a wolffd@0: % SURF object is used. If the lattice is hexagonal - or anything else than wolffd@0: % rectangular in general - the result is not strictly what is looked wolffd@0: % for, especially if the map is small. wolffd@0: % wolffd@0: % EXAMPLES wolffd@0: % wolffd@0: %% Make random data, normalize it, and give component names wolffd@0: %% Make a map wolffd@0: % wolffd@0: % data=som_data_struct(rand(1000,3),'comp_names',{'One','Two','Three'}); wolffd@0: % data=som_normalize(data,'var'); wolffd@0: % map=som_make(data); wolffd@0: % wolffd@0: %% Do the basic visualization with som_show: u-matrix and all wolffd@0: %% component planes wolffd@0: % wolffd@0: % som_show(map); wolffd@0: % wolffd@0: %% The values shown in the colorbar are denormalized codebook values wolffd@0: %% (if denormalization is possible). To view the actual values, use wolffd@0: %% the ..., 'norm', 'n' argument pair. wolffd@0: % wolffd@0: % som_show(map,'norm','n') wolffd@0: % wolffd@0: %% Something more complex: wolffd@0: %% Show 1-2. Component planes 1 and 2 (variables 'One' and 'Two') wolffd@0: %% 3. U-matrix that is calculated only using variables wolffd@0: %% 'One' and 'Two' wolffd@0: %% with title '1,2 only' wolffd@0: %% 4. U-matrix that is calculated using all variables with the wolffd@0: %% deafult title 'U-matrix' wolffd@0: %% 5. The color code (in c) with title 'Color code' wolffd@0: %% 6. Component plane 3 (variable 'Three') wolffd@0: %% and use vertical colorbars and and the values wolffd@0: %% But first: make a continuous color code (see som_colorcode) wolffd@0: % wolffd@0: % c=som_colorcode(map,'rgb1'); wolffd@0: % wolffd@0: % som_show(map,'comp',[1 2],'umat',{1:2,'1,2 only'},'umat','all', ... wolffd@0: % 'color',{c,'Color code'},'bar','vert','norm','n','comp',3) wolffd@0: % wolffd@0: % SEE ALSO wolffd@0: % wolffd@0: % som_show_add Show hits, labels and trajectories on SOM_SHOW visualization. wolffd@0: % som_show_clear Clear hit marks, labels or trajectories from current figure. wolffd@0: % som_umat Compute unified distance matrix of self-organizing map. wolffd@0: % som_grid Visualization of a SOM grid. wolffd@0: % som_cplane Visualization of component, u-matrix and color planes. wolffd@0: wolffd@0: % Copyright (c) 1997-2000 by the SOM toolbox programming team. wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 1.0beta johan 100298 wolffd@0: % Version 2.0beta johan 201099 juuso 181199 johan 011299-100200 wolffd@0: % juuso 130300 190600 wolffd@0: wolffd@0: %% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: error(nargchk(1,Inf,nargin)) % check no. of input args wolffd@0: wolffd@0: if isstruct(sMap), % check map wolffd@0: [tmp,ok,tmp]=som_set(sMap); wolffd@0: if all(ok) & strcmp(sMap.type,'som_map') wolffd@0: ; wolffd@0: else wolffd@0: error('Map struct is invalid!'); wolffd@0: end wolffd@0: else wolffd@0: error('Requires a map struct!') wolffd@0: end wolffd@0: wolffd@0: munits=size(sMap.codebook,1); % numb. of map units wolffd@0: d=size(sMap.codebook,2); % numb. of components wolffd@0: msize=sMap.topol.msize; % size of the map wolffd@0: lattice=sMap.topol.lattice; % lattice wolffd@0: wolffd@0: if length(msize)>2 wolffd@0: error('This visualizes only 2D maps!') wolffd@0: end wolffd@0: wolffd@0: if rem(length(varargin),2) wolffd@0: error('Mismatch in identifier-value pairs.'); wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % read in optional arguments wolffd@0: wolffd@0: if isempty(varargin), wolffd@0: varargin = { 'umat','all','comp','all'}; wolffd@0: end wolffd@0: wolffd@0: %% check the varargin and build visualization infostrcuts wolffd@0: % Vis: what kind of planes, in which order, what are the values in wolffd@0: % the units wolffd@0: % Vis_param: general properties wolffd@0: % see subfunction wolffd@0: wolffd@0: % The try-catch construction is here just for avoiding the wolffd@0: % possible termination to happen in subfunction because an error wolffd@0: % message containing subfunction line numbers etc. might be confusing, as wolffd@0: % there probably is nothing wrong with the subfunction but with the wolffd@0: % input. Ok, this isn't proper programming sytle... wolffd@0: wolffd@0: try wolffd@0: [Plane, General]= check_varargin(varargin, munits, d, sMap.name); wolffd@0: catch wolffd@0: error(lasterr); wolffd@0: end wolffd@0: wolffd@0: % Set default values for missing ones wolffd@0: wolffd@0: % No planes at all (only general properties given in varargin): wolffd@0: % set default visualization wolffd@0: wolffd@0: if isempty(Plane) wolffd@0: varargin = [varargin, { 'umat','all','comp','all'}]; wolffd@0: % and again we go... wolffd@0: try wolffd@0: [Plane, General]= check_varargin(varargin, munits, d, sMap.name); wolffd@0: catch wolffd@0: error(lasterr); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % set defaults for general properties wolffd@0: wolffd@0: if isempty(General.colorbardir) wolffd@0: General.colorbardir='vert'; wolffd@0: end wolffd@0: wolffd@0: if isempty(General.scale) wolffd@0: General.scale='denormalized'; wolffd@0: end wolffd@0: wolffd@0: if isempty(General.size) wolffd@0: General.size=1; wolffd@0: end wolffd@0: wolffd@0: if isempty(General.edgecolor) wolffd@0: General.edgecolor='none'; wolffd@0: end wolffd@0: wolffd@0: %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: % get rid of an annoying warning: "RGB color data not yet supported in wolffd@0: % Painter's mode." wolffd@0: %set(gcf, 'renderer','zbuffer'); wolffd@0: %% -> a much more annoying thing results: the output to PostScript is wolffd@0: %% as bitmap, making the files over 6MB in size... wolffd@0: wolffd@0: n=length(Plane); % the number of subfigures wolffd@0: wolffd@0: % get the unique component indices wolffd@0: c=General.comp(General.comp>0); wolffd@0: c=setdiff(unique(c),[0 -1]); wolffd@0: c=c(~isnan(c)); wolffd@0: wolffd@0: % estimate the suitable dimension for wolffd@0: if isempty(General.subplots), wolffd@0: y=ceil(sqrt(n)); % subplots wolffd@0: x=ceil(n/y); wolffd@0: else wolffd@0: y = General.subplots(2); wolffd@0: x = General.subplots(1); wolffd@0: if y*x=' num2str(n)]); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: clf; % clear figure wolffd@0: wolffd@0: for i=1:n, % main loop wolffd@0: h_axes(i,1)=subplot(x,y,i); % open a new subplot wolffd@0: wolffd@0: % Main switch: select function according to the flags set in comps wolffd@0: wolffd@0: switch Plane{i}.mode wolffd@0: wolffd@0: case 'comp' wolffd@0: %%% Component plane wolffd@0: wolffd@0: tmp_h=som_cplane(lattice,msize, sMap.codebook(:,General.comp(i)), ... wolffd@0: General.size); wolffd@0: set(tmp_h,'EdgeColor', General.edgecolor); wolffd@0: set(h_axes(i),'Tag','Cplane'); wolffd@0: h_label(i,1)=xlabel(sMap.comp_names{General.comp(i)}); wolffd@0: wolffd@0: wolffd@0: case 'compi' wolffd@0: %%% Component plane (interpolated shading) wolffd@0: wolffd@0: tmp_h=som_grid(lattice, msize, 'surf', sMap.codebook(:,Plane{i}.value), ... wolffd@0: 'Marker', 'none', 'Line', 'none'); wolffd@0: set(h_axes(i),'Tag','CplaneI'); wolffd@0: h_label(i,1)=xlabel(sMap.comp_names(Plane{i}.value)); wolffd@0: vis_PlaneAxisProperties(gca,lattice,msize,NaN); wolffd@0: wolffd@0: case 'color' wolffd@0: %%% Color plane wolffd@0: wolffd@0: tmp_h=som_cplane(lattice,msize,Plane{i}.value,General.size); wolffd@0: set(tmp_h,'EdgeColor','none'); wolffd@0: set(h_axes(i),'Tag','Cplane'); wolffd@0: h_label(i,1)=xlabel(Plane{i}.name); wolffd@0: wolffd@0: wolffd@0: case 'colori' wolffd@0: %%% Color plane (interpolated shading) wolffd@0: wolffd@0: tmp_h=som_grid(lattice, msize, 'surf', Plane{i}.value, 'Marker', 'none', ... wolffd@0: 'Line', 'none'); wolffd@0: set(h_axes(i),'Tag','CplaneI'); wolffd@0: h_label(i,1)=xlabel(Plane{i}.name); wolffd@0: vis_PlaneAxisProperties(gca,lattice,msize,NaN); wolffd@0: wolffd@0: case 'empty' wolffd@0: %%% Empty plane wolffd@0: wolffd@0: tmp_h=som_cplane(lattice,msize,'none'); wolffd@0: h_label(i,1)=xlabel(Plane{i}.name); wolffd@0: set(h_axes(i),'Tag','Cplane'); wolffd@0: wolffd@0: case 'umat' wolffd@0: %%% Umatrix wolffd@0: wolffd@0: u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'median',... wolffd@0: 'mask',sMap.mask(Plane{i}.value)); u=u(:); wolffd@0: tmp_h=som_cplane([lattice 'U'],msize,u); wolffd@0: set(tmp_h,'EdgeColor','none'); wolffd@0: set(h_axes(i),'Tag','Uplane'); wolffd@0: h_label(i,1)=xlabel(Plane{i}.name); wolffd@0: wolffd@0: case 'umati' wolffd@0: %%% Umatrix (interpolated shading) wolffd@0: wolffd@0: u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'mean',... wolffd@0: 'mask',sMap.mask(Plane{i}.value)); u=u(1:2:end,1:2:end); wolffd@0: u=u(:); wolffd@0: tmp_h=som_grid('rect', msize, 'surf', u, ... wolffd@0: 'Marker', 'none', 'Line', 'none', ... wolffd@0: 'coord', som_vis_coords(lattice,msize)); wolffd@0: set(h_axes(i),'Tag','UplaneI'); wolffd@0: h_label(i,1)=xlabel(Plane{i}.name); wolffd@0: vis_PlaneAxisProperties(gca,lattice,msize,NaN); wolffd@0: wolffd@0: otherwise wolffd@0: error('INTERNAL ERROR: unknown visualization mode.'); wolffd@0: end wolffd@0: wolffd@0: %%% Adjust axis ratios to optimal (only 2D!) and put the wolffd@0: %%% title as close to axis as possible wolffd@0: wolffd@0: set(h_label,'Visible','on','verticalalignment','top'); wolffd@0: set(gca,'plotboxaspectratio',[msize(2) msize(1) msize(1)]); wolffd@0: wolffd@0: %%% Draw colorbars if they are turned on and the plane is umat or c-plane wolffd@0: wolffd@0: if General.comp(i)> -1 & ~strcmp(General.colorbardir,'none'), wolffd@0: h_colorbar(i,1)=colorbar(General.colorbardir); % colorbars wolffd@0: else wolffd@0: h_colorbar(i,1)=-1; wolffd@0: General.comp(i)=-1; wolffd@0: end wolffd@0: end %% main loop ends wolffd@0: wolffd@0: % Set window name wolffd@0: wolffd@0: set(gcf,'Name',[ 'Map name: ' sMap.name]); wolffd@0: wolffd@0: %% Set axes handles to the UserData field (for som_addxxx functions wolffd@0: %% and som_recolorbar) wolffd@0: %% set component indexes and normalization struct for som_recolorbar wolffd@0: wolffd@0: SOM_SHOW.subplotorder=h_axes; wolffd@0: SOM_SHOW.msize=msize; wolffd@0: SOM_SHOW.lattice=lattice; wolffd@0: SOM_SHOW.dim=d; wolffd@0: SOM_SHOW.comps=General.comp; wolffd@0: SOM_SHOW.comp_norm=sMap.comp_norm; %(General.comp(find(General.comp>0))); wolffd@0: wolffd@0: set(gcf,'UserData', SOM_SHOW); wolffd@0: wolffd@0: % Set text property 'interp' to 'none' in title texts wolffd@0: wolffd@0: set(h_label,'interpreter','none'); wolffd@0: wolffd@0: h_colorbar=som_recolorbar('all', 3, General.scale); %refresh colorbars wolffd@0: wolffd@0: % Set a movable text to lower corner pointsize 12. wolffd@0: wolffd@0: vis_footnote(General.footnote); vis_footnote(12); wolffd@0: wolffd@0: % set colormap wolffd@0: colormap(General.colormap); wolffd@0: wolffd@0: %% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: if nargout > 0 wolffd@0: h.plane=h_axes; h.colorbar=h_colorbar; h.label=h_label; wolffd@0: end wolffd@0: wolffd@0: wolffd@0: %%%%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function [Plane, General]=check_varargin(args, munits, dim, name) wolffd@0: wolffd@0: % args: varargin of the main function wolffd@0: % munits: number of map units wolffd@0: % dim: map codebook dimension wolffd@0: % name: map name wolffd@0: % Define some variables (they must exist later) wolffd@0: wolffd@0: Plane={}; % stores the visualization data for each subplot wolffd@0: General.comp=[]; % information stored on SOM_SHOW figure (which component) wolffd@0: General.size=[]; % unit size wolffd@0: General.scale=[]; % normalization wolffd@0: General.colorbardir=[]; % colorbar direction wolffd@0: General.edgecolor=[]; % edge colors wolffd@0: General.footnote=name; % footnote text wolffd@0: General.colormap=colormap; % default colormap (used to be gray(64).^.5;) wolffd@0: General.subplots=[]; % number of subplots in y- and x-directions wolffd@0: wolffd@0: for i=1:2:length(args), wolffd@0: %% Check that all argument types are strings wolffd@0: wolffd@0: if ~ischar(args{i}), wolffd@0: error('Invalid input identifier names or input argument order.'); wolffd@0: end wolffd@0: wolffd@0: %% Lower/uppercase in identifier types doesn't matter: wolffd@0: wolffd@0: identifier=lower(args{i}); % identifier (lowercase) wolffd@0: value=args{i+1}; wolffd@0: wolffd@0: %%% Check first the identifiers that define planes and get values wolffd@0: %%% to the visualization data struct array Plane. wolffd@0: %%% (comps,compi,umat,color,empty) Note that name, value and comp_ wolffd@0: %%% must be specified in these cases wolffd@0: %%% comp_ are collected to comp in order. This is stored to the wolffd@0: %%% SOM_SHOW user property field to give information for SOM_RECOLROBAR wolffd@0: %%% how to operate, i.e., which component is in which subplot: wolffd@0: %%% comp(i)=0: draw colorbar, but no normalization (umat) wolffd@0: %%% comp(i)=1...N: a component plane of variable comp(i) wolffd@0: %%% comp(i)=-1: no colorbar (color or empty plane) wolffd@0: wolffd@0: switch identifier wolffd@0: case {'comp','compi'} wolffd@0: %%% Component planes: check values & set defaults wolffd@0: wolffd@0: if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value), wolffd@0: error([ 'A vector argument or string ''all'' expected for ''' ... wolffd@0: identifier '''.']) wolffd@0: end wolffd@0: if isempty(value) wolffd@0: value=1:dim; wolffd@0: elseif ischar(value), wolffd@0: if ~strcmp(value,'all') wolffd@0: error([ 'Only string value ''all'' is valid for ''' ... wolffd@0: identifier '''.']); wolffd@0: else wolffd@0: value=1:dim; wolffd@0: end wolffd@0: else wolffd@0: value=round(value); wolffd@0: if min(value)<1 | max(value)>dim, wolffd@0: error([ 'Component indices out of range in ''' identifier '''.']) wolffd@0: end wolffd@0: end wolffd@0: if size(value,1)==1, value=value';end wolffd@0: comp_=value; wolffd@0: name=[]; % name is taken form sMap by index in main loop wolffd@0: wolffd@0: case {'umat','umati'} wolffd@0: %%% Check first the possible cell input wolffd@0: wolffd@0: if iscell(value), wolffd@0: if ndims(value) ~= 2 | any(size(value) ~= [1 2]) | ... wolffd@0: ~vis_valuetype(value{2},{'string'}), wolffd@0: error('Cell input for ''umat'' has to be of form {vector, string}.'); wolffd@0: else wolffd@0: name=value{2}; value=value{1}; wolffd@0: end wolffd@0: else wolffd@0: name='U-matrix'; % no cell: default title is set wolffd@0: end wolffd@0: if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value), wolffd@0: error('Vector, string ''all'', or cell {vector, string} expected for ''umat''.') wolffd@0: end wolffd@0: if isempty(value) wolffd@0: value=1:dim; wolffd@0: elseif ischar(value), wolffd@0: if ~strcmp(value,'all') wolffd@0: error('Only string value ''all'' is valid for ''umat''.') wolffd@0: else wolffd@0: value=1:dim; wolffd@0: end wolffd@0: else wolffd@0: value=unique(round(value)); wolffd@0: end wolffd@0: if min(value)<1 | max(value)>dim, wolffd@0: error('Component indices out of range in ''umat''.') wolffd@0: end wolffd@0: wolffd@0: if size(value,1)==1, value=value';end wolffd@0: comp_=0; wolffd@0: wolffd@0: case 'empty' wolffd@0: %%% Empty plane: check values & set defaults wolffd@0: wolffd@0: if ~vis_valuetype(value,{'string'}), wolffd@0: error('A string value for title name expected for ''empty''.'); wolffd@0: end wolffd@0: name=value; wolffd@0: comp_=-1; wolffd@0: wolffd@0: case { 'color','colori'} wolffd@0: %%% Color plane: check values & set defaults wolffd@0: wolffd@0: % Check first the possible cell input wolffd@0: if iscell(value), wolffd@0: if ndims(value)~=2 | any(size(value) ~= [1 2]) | ... wolffd@0: ~vis_valuetype(value{2},{'string'}), wolffd@0: error([ 'Cell input for ''' identifier ... wolffd@0: ''' has to be of form {M, string}.']); wolffd@0: else wolffd@0: name=value{2}; value=value{1}; wolffd@0: end wolffd@0: else wolffd@0: name='Color code'; % no cell: default title is set wolffd@0: end wolffd@0: if size(value,1)~=munits | ... wolffd@0: (~vis_valuetype(value,{'nx3rgb'}) & ... wolffd@0: ~vis_valuetype(value,{'nx1'}) & ... wolffd@0: ~vis_valuetype(value,{'nx1xm'}) & ... wolffd@0: ~vis_valuetype(value,{'nx3xdimrgb'})), wolffd@0: error(['Mx3 or Mx3xN RGBmatrix, Mx1 or Mx1xN matrix, cell '... wolffd@0: '{RGBmatrix, string},' ... wolffd@0: ' or {matrix, string} expected for ''' identifier '''.']); wolffd@0: end wolffd@0: wolffd@0: % if colormap is fixed, we don't draw colorbar (comp_ flag is -1) wolffd@0: % if colormap is indexed, we draw colorbar as in umat (comp_=0) wolffd@0: wolffd@0: if size(value,2)==3 wolffd@0: comp_=-1; wolffd@0: else wolffd@0: comp_=0; wolffd@0: end wolffd@0: wolffd@0: %%%% The next things are general properties of the visualization--- wolffd@0: %%%% wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: case 'size' wolffd@0: %%% Unit size: check & set wolffd@0: wolffd@0: if ~vis_valuetype(value,{'1x1',[munits 1]}) wolffd@0: error('A munits x 1 vector or a scalar expected for ''size''.') wolffd@0: end wolffd@0: if isempty(value), wolffd@0: General.size=1; wolffd@0: else wolffd@0: General.size=value; wolffd@0: end wolffd@0: wolffd@0: case 'bar' wolffd@0: %%% Colorbar existence & direction: check & set wolffd@0: wolffd@0: if ~vis_valuetype(value,{'string'}) wolffd@0: error('String value expected for ''bar''.') wolffd@0: elseif isempty(value) wolffd@0: value='vert'; wolffd@0: end wolffd@0: if any(strcmp(value,{'vert','horiz','none'})), wolffd@0: General.colorbardir=value; wolffd@0: else wolffd@0: error('String ''vert'', ''horiz'' or ''none'' expected for ''bar''.'); wolffd@0: end wolffd@0: wolffd@0: case 'norm' wolffd@0: %%% Value normalization: check & set wolffd@0: wolffd@0: if ~vis_valuetype(value,{'string'}) wolffd@0: error('String ''n'' or ''d'' expected for ''norm''.'); wolffd@0: elseif isempty(value) wolffd@0: value='n'; wolffd@0: end wolffd@0: if strcmp(value(1),'n'), wolffd@0: General.scale='normalized'; wolffd@0: elseif strcmp(value(1),'d'), wolffd@0: General.scale='denormalized'; wolffd@0: else wolffd@0: error('String ''n(ormalized)'' or ''d(enormalized)'' expected for ''norm''.'); wolffd@0: end wolffd@0: wolffd@0: case 'edge' wolffd@0: %%% Edge on or off : check % set wolffd@0: wolffd@0: if ~vis_valuetype(value,{'string'}) & ~isempty(value), wolffd@0: error('String value expected for ''edge''.') wolffd@0: elseif ~isempty(value), wolffd@0: switch value wolffd@0: case 'on' wolffd@0: General.edgecolor='k'; wolffd@0: case 'off' wolffd@0: General.edgecolor='none'; wolffd@0: otherwise wolffd@0: error('String value ''on'' or ''off'' expected for ''edge''.') wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: case 'footnote' wolffd@0: %%% Set the movable footnote text wolffd@0: wolffd@0: if ~vis_valuetype(value,{'string'}) wolffd@0: if ~isempty(value), wolffd@0: error('String value expected for ''footnote''.'); wolffd@0: else wolffd@0: General.footnote=sMap.name; wolffd@0: end wolffd@0: else wolffd@0: General.footnote=value; wolffd@0: end wolffd@0: wolffd@0: case 'colormap' wolffd@0: %%% Set the colormap wolffd@0: if isempty(value) wolffd@0: General.colormap=gray(64).^2; wolffd@0: elseif ~vis_valuetype(value,{'nx3rgb'}) wolffd@0: error('Colormap is invalid!'); wolffd@0: else wolffd@0: General.colormap=value; wolffd@0: end wolffd@0: wolffd@0: case 'subplots' wolffd@0: %%% set the number of subplots wolffd@0: if ~vis_valuetype(value,{'1x2'}) & ~vis_valuetype(value,{'2x1'}) wolffd@0: error('Subplots grid size is invalid!'); wolffd@0: else wolffd@0: General.subplots=value; wolffd@0: end wolffd@0: wolffd@0: otherwise wolffd@0: %%% Unknown identifier wolffd@0: wolffd@0: error(['Invalid argument identifier ''' identifier '''!']); wolffd@0: end wolffd@0: wolffd@0: %%% Set new entry to the Plane array if the indentifier means wolffd@0: %%% making a new plane/planes wolffd@0: wolffd@0: tail=length(Plane); wolffd@0: switch identifier wolffd@0: case {'comp','compi'} wolffd@0: for i=1:length(value) wolffd@0: Plane{tail+i}.mode=identifier; wolffd@0: Plane{tail+i}.value=value(i); wolffd@0: Plane{tail+i}.name=name; % not used actually wolffd@0: end wolffd@0: General.comp = [General.comp; comp_]; wolffd@0: case {'umat','umati','empty'} wolffd@0: Plane{tail+1}.mode=identifier; wolffd@0: Plane{tail+1}.value=value; wolffd@0: Plane{tail+1}.name=name; wolffd@0: General.comp = [General.comp; comp_]; wolffd@0: case {'color','colori'}, wolffd@0: for i=1:size(value,3), wolffd@0: Plane{tail+i}.mode=identifier; wolffd@0: Plane{tail+i}.name=[name '_' num2str(i)]; wolffd@0: Plane{tail+i}.value=value(:,:,i); wolffd@0: General.comp = [General.comp; comp_]; wolffd@0: end wolffd@0: if size(value,3)==1, wolffd@0: Plane{tail+1}.name=name; wolffd@0: end wolffd@0: otherwise wolffd@0: ; % do nothing wolffd@0: end wolffd@0: end