How can I use the scatter
function in GNU Octave in order to assign colors to each plotted value ?
You have to change colormap and 4th parameter of octave's scatter. The parameter is vector 1xn indexing colormap. You can have maximally 255^3 vectors. And how to do that?
clf;
x = randn (100, 1);
y = randn (100, 1);
cmap=[];
for R = 1:255
for G = 1:255
for B = 1:255
if (size(cmap) ./ [1,3] == size(x))
break;
endif
cmap=[cmap;R/255,G/255,B/255];
endfor
if (size(cmap) ./ [1,3] == size(x))
break;
endif
endfor
if (size(cmap) ./ [1,3] == size(x))
break;
endif
endfor
colormap(cmap);
scatter(x,y,20, 1:100);
Here's a nice illustrative example:
X = linspace(0, 4 * pi, 100); % Create points (100 elements)
Y = 100 * sin(X);
S = Y + 100; % Sizes array. All values need
% to be larger than 0
C = [linspace(0,1,100); ones(1,100); ones(1,100)]'; % create hsv triplets at full
% saturation and value that
% cover the whole colour
% (i.e. hues) spectrum
C = hsv2rgb(C); % convert to rgb triplets; to
% be used as a 'colour array'
scatter(X,Y,S,C,'filled','MarkerEdgeColor','k'); % fill bubbles, black border