comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_plotplane.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 h=som_plotplane(varargin)
2
3 %SOM_PLOTPLANE Visualize the map prototype vectors as line graphs
4 %
5 % h=som_plotplane(lattice, msize, data, [color], [scaling], [pos])
6 % h=som_plotplane(topol, data, [color], [scaling], [pos])
7 %
8 % som_plotplane('hexa',[5 5], rand(25,4), jet(25))
9 % som_plotplane(sM, sM.codebook)
10 %
11 % Input and output arguments ([]'s are optional)
12 % lattice (string) grid 'hexa' or 'rect'
13 % msize (vector) size 1x2, defines the grid size
14 % (matrix) size Mx2, defines explicit coordinates: in
15 % this case the first argument does not matter
16 % topol (struct) map or topology struct
17 % data (matrix) Mxd matrix, M=prod(msize)
18 % [color] (matrix) size Mx3, gives an individual color for each graph
19 % (string) ColorSpec gives the same color for each
20 % graph, default is 'k' (black)
21 % [scaling] (string) 'on' or 'off', default is 'on'
22 % [pos] (vector) 1x2 vector that determines translation.
23 % Default is no translation.
24 %
25 % h (vector) the object handles for the LINE objects
26 %
27 % If scaling is set on, the data will be linearly scaled in each
28 % unit so that min and max values span from lower to upper edge
29 % in each unit. If scaling is 'off', the proper scaling is left to
30 % the user: values in range [-.5,.5] will be plotted within the limits of the
31 % unit while values exceeding this range will be out of the unit.
32 % Axis are set as in SOM_CPLANE.
33 %
34 % For more help, try 'type som_plotplane' or check out online documentation.
35 % See also SOM_PLANE, SOM_PIEPLANE, SOM_BARPLANE
36
37 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %
39 % som_plotplane
40 %
41 % PURPOSE
42 %
43 % Visualizes the map prototype vectors as line graph
44 %
45 % SYNTAX
46 %
47 % h = som_plotplane(topol, data)
48 % h = som_plotplane(lattice, msize, data)
49 % h = som_plotplane(..., color)
50 % h = som_plotplane(..., color, scaling)
51 % h = som_plotplane(..., color, scaling, pos)
52 %
53 % DESCRIPTION
54 %
55 % Visualizes the map prototype vectors as line graph
56 %
57 % KNOWN BUGS
58 %
59 % It is not possible to specify explicit coordinates for map
60 % consistig of just one unit as then the msize is interpreted as
61 % map size.
62 %
63 % FEATURES
64 %
65 % - the colors are fixed: changing colormap in the figure (see
66 % COLORMAP) will not affect the coloring of the plots
67 %
68 % REQUIRED INPUT ARGUMENTS
69 %
70 % lattice The basic topology
71 %
72 % (string) 'hexa' or 'rect' positions the plots according to hexagonal or
73 % rectangular map lattice.
74 %
75 % msize The size of the map grid
76 %
77 % (vector) [n1 n2] vector defines the map size (height n1 units, width n2
78 % units, total M=n1 x n2 units). The units will be placed to their
79 % topological locations in order to form a uniform hexagonal or
80 % rectangular grid.
81 % (matrix) Mx2 matrix defines arbitary coordinates for the M units.
82 % In this case the argument 'lattice' has no effect.
83 %
84 % topol Topology of the map grid
85 %
86 % (struct) map or topology struct from which the topology is taken
87 %
88 % data The data to be visualized
89 %
90 % (matrix) Mxd matrix of data vectors.
91 %
92 % OPTIONAL INPUT ARGUMENTS
93 %
94 % If unspecified or given empty values ('' or []), default values
95 % will be used for optional input arguments.
96 %
97 % color The color of the plots
98 %
99 % (string) Matlab's ColorSpec (see help plot) string gives the same color
100 % for each line.
101 %
102 % (matrix) Mx3 matrix assigns an RGB color determined by the Nth row of
103 % the matrix to the Nth plot.
104 %
105 % (vector) 1x3 RGB vector gives the same color for each line.
106 %
107 % scaling The data scaling mode
108 %
109 % (string) 'on or 'off': if scaling is set on, the data will be
110 % linearly scaled in each unit so that min and max values span from
111 % lower to upper edge in each unit. If scaling is 'off', the proper
112 % scaling is left to the user: values in range [-.5,.5] will be plotted
113 % within the limits of the unit while values exceeding this
114 % range will be out of the unit.
115 %
116 % pos Position of the origin
117 %
118 % (vector) This is meant for drawing the plane in arbitary location in a
119 % figure. Note the operation: if this argument is given, the
120 % axis limits setting part in the routine is skipped and the limits
121 % setting will be left to be done by MATLAB's
122 % defaults. By default no translation is done.
123 %
124 % OUTPUT ARGUMENTS
125 %
126 % h (scalar) Handle to the created patch object
127 %
128 % OBJECT TAG
129 %
130 % Object property 'Tag' is set to 'planePlot'.
131 %
132 % EXAMPLES
133 %
134 % %%% Create the data and make a map
135 %
136 % data=rand(1000,20); map=som_make(data);
137 %
138 % %%% Create a 'gray' colormap that has 64 levels
139 %
140 % color_map=gray(64);
141 %
142 % %%% Draw plots using red color
143 %
144 % som_plotplane(map, map.codebook,'r');
145 %
146 % %%% Calculate hits on the map and calculate colors so that
147 % black = min. number of hits and white = max. number of hits
148 %
149 % hit=som_hits(map,data); color=som_normcolor(hit(:),color_map);
150 %
151 % %%% Draw plots again. Now the gray level indicates the number of hits to
152 % each node
153 %
154 % som_plotplane(map, map.codebook, color);
155 %
156 % SEE ALSO
157 %
158 % som_cplane Visualize a 2D component plane, u-matrix or color plane
159 % som_barplane Visualize the map prototype vectors as bar diagrams.
160 % som_pieplane Visualize the map prototype vectors as pie charts
161
162 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
163 % http://www.cis.hut.fi/projects/somtoolbox/
164
165 % Version 2.0beta Johan 160799 juuso 151199 070600
166
167 %%% Init & Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168
169 [nargin, lattice, msize, data, color, scaling, pos] = vis_planeGetArgs(varargin{:});
170 error(nargchk(3, 5, nargin)); % check no. of input args is correct
171
172 s=0.8; % size of plot
173
174 if nargin < 6 | isempty(pos)
175 pos=NaN;
176 end
177
178 if nargin < 5 | isempty(scaling)
179 scaling='on';
180 elseif ~vis_valuetype(scaling,{'string'}) | ...
181 ~any(strcmp(scaling,{'on','off'})),
182 error('Scaling should be string ''on'' or ''off''.');
183 end
184
185 l=size(data,2);
186
187 if ~isnumeric(msize) | ndims(msize) ~= 2 | size(msize,2)~=2,
188 error('msize has to be 1x2 grid size vector or a Nx2 coordinate matrix.');
189 elseif size(msize,1) == 1,
190 xdim=msize(2);
191 ydim=msize(1);
192 N=xdim*ydim;
193 y=repmat(repmat([1:ydim]',xdim,1),1,l);
194 x=reshape(repmat([1:xdim],ydim*l,1),l,N)';
195 else
196 x=repmat(msize(:,1),1,l);y=repmat(msize(:,2),1,l);
197 N=size(msize,1);
198 lattice='rect';
199 if isnan(pos),
200 pos=[0 0];
201 end
202 end
203
204 switch lattice
205 case {'hexa', 'rect'}
206 ;
207 otherwise
208 error(['Lattice' lattice ' not implemented!']);
209 end
210
211 if ~isnumeric(data) | size(data,1) ~= N
212 error('Data matrix is invalid or has wrong size!');
213 end
214
215 if nargin < 4 | isempty(color),
216 color='k';
217 elseif vis_valuetype(color, {'colorstyle',[N 3]}),
218 if ischar(color) & strcmp(color,'none'),
219 error('Colorstyle ''none'' not allowed in som_plotplane.');
220 end
221 elseif vis_valuetype(color,{'1x3rgb'})
222 ;
223 elseif ~vis_valuetype(color,{'nx3rgb',[N 3]},'all'),
224 error('The color matrix has wrong size or contains invalid RGB values or colorstyle.');
225 end
226
227 [linesx, linesy]=vis_line(data,scaling);
228
229 %%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231 % Making the lattice.
232 % Command view([0 90]) shows the map in 2D properly oriented
233
234 switch lattice
235 case 'hexa'
236 t=find(rem(y(:,1),2)); % move even rows by .5
237 x(t,:)=x(t,:)-.5;
238 x=(x./s+linesx).*s+.5; y=(y./s+linesy).*s; % scale with s
239 case 'rect'
240 x=(x./s+linesx).*s; y=(y./s+linesy).*s; % scale with s
241 end
242
243 %% Draw the map! ...
244
245 h_=plot(x',y');
246
247 if size(color,1) == 1
248 set(h_,'Color',color);
249 else
250 for i=1:N,
251 set(h_(i,:),'Color',color(i,:));
252 end
253 end
254
255 if ~isnan(pos)
256 x=x+pos(1);y=y+pos(2); % move upper left corner
257 end % to pos(1),pos(2)
258
259 %% Set axes properties
260
261 ax=gca;
262 vis_PlaneAxisProperties(ax, lattice, msize, pos);
263
264 %%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 set(h_,'Tag','planePlot'); % tag the lineobject
267
268 if nargout>0, h=h_; end % Set h only,
269 % if there really is output
270
271 %% Subfuntion %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
273 function [x,y]=vis_line(data, scaling)
274
275 s=size(data);
276 % normalization between [0,1] if scaling is on
277 if strcmp(scaling,'on')
278 mn=repmat(min(data,[],2),1,s(2));
279 mx=repmat(max(data,[],2),1,s(2));
280 y=-((data-mn)./(mx-mn))+.5;
281 else % -sign is beacuse we do axis ij
282 y=-data;
283 end
284
285 x=repmat(linspace(-.5, .5, size(data,2)), size(data,1),1);