Octave plot different colour for every point

1k views Asked by At

I am having a specific problem. Firstly I am using octave. I have a dataset where every row is of the following format:

datarow = [ x, y, z, colourIndex];

The length of the dataset is irrelevant, but suppose it is 10. I want to be able to plot the 3d plot with every point having a colour of its specific color index. Of course I know that I can use a for loop and add every point individually, but I find it hard to believe that there isn't already some way to do that using vectors.

So far I have tried:

map = cool(); #init colormap
data = initializeData(); #initialize data
plot3(data(:,1),data(:,2),data(:,3),"c" , map(data(:,4))); #doesn't work

Any ideas if it's possible to do a one-liner for my issue?

1

There are 1 answers

0
ederag On BEST ANSWER

Use scatter3:

N_colors = 64;
colormap(cool(N_colors));
# point positions (your data(:, 1:3))
[x, y, z] = peaks (20);
# these are the color indexes in the colormap (your data(:, 4))
c_index = fix(rand(size(x)) * N_colors);
marker_size = 8;

scatter3(x(:), y(:), z(:), marker_size, c_index(:))

enter image description here