Egor Levchenko
Egor Levchenko

Reputation: 59

How to color the dots in scatter3 based on data from 4th variable?

I have 3D coordinates (x,y,z) of channels located inside the brain. I am plotting them on the brain map using scatter3 function to obtain the picture below (now the coordinates are not really true, but it doesn't matter for now): Brain picture with channels The colour now is just randomly assigned, but I would like to colour the each dot on my scatter3 based on data from 4th variable. The 4th variable has information about the number of signals detected in that channel. For example, I have 80 channels with X, Y, Z coordinates (80x3) and one more variable N with number of signals (80x1). How is it possible to colour my 80 channels based on N? I would like to make visually interpretable with a colorbar nearby - for example, the darker the point the higher the number of signals were detected in that channel.

Now I have only this:

scatter3(sw_chs_coords(:,2), sw_chs_coords(:,1), sw_chs_coords(:,3), []); 

xlabel('X')
ylabel('Y')
zlabel('Z')
hold on
view(0, 0)

Can you help me please with that?

Upvotes: 2

Views: 407

Answers (1)

Max
Max

Reputation: 4045

This sounds just as the 5th input of scatter3

scatter3(X,Y,Z,S,C) draws each circle with the color specified by C.

  • If C is a RGB triplet or character vector or string containing a color name, then all circles are plotted with the specified color.
  • If C is a three column matrix with the number of rows in C equal to the length of X, Y, and Z, then each row of C specifies an RGB color
    value for the corresponding circle.
  • If C is a vector with length equal to the length of X, Y, and Z, then the values in C are linearly mapped to the colors in the current colormap.

So you can either specify RGB values (that is a 3x1 array in [0 1] or x/256 of a normal RGB value) or you provide just another information vector and the thing is set to a colormap representing the continuous value in the vector.

Upvotes: 2

Related Questions