0

I am trying to create a scatterplot with more than the 8 default Matlab colors, but when I create a colormap I get the error: Error using set Error setting property 'MarkerFaceColor' of class 'Line': Color value must be a 3 element vector. Right now I am creating the scatterplot with:

colors = hsv(18);
gscatter3(x,y,z,idx, colors, {'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'},15);

I also tried manually creating a vector for the colors but still could not get anything to work other than the 8 default colors, i.e. 'b','g','r',etc. Does anyone know how to get more colors to work?

Morgan
  • 3
  • 3

1 Answers1

0

I was also unable to graph it using the gscatter3() function. Just in case you'd like to use the built-in scatter3() function as an alternative. Note that this method uses RGB (BGR) triplets. The number of triplets must match the number of data points expected to be plotted. In the example below I generated random colours. The expected range of any RGB intensity is from (0,1) on this scale for the scatter3() function.

3D RGB Triplet Scatter Plot

%Random samples/signal data%
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
z = linspace(0,3*pi,200);
x = x';
y = y';
z = z';

Marker_Size = 20;

Signal_Length = length(x);

RGB_Triplets = zeros(Signal_Length,3);

%***************************************************%
%Here the RGB_Triplets can be written to any value%
%***************************************************%
%Example%
for Row = 1: +1: Signal_Length
Maximum_Intensity_Value = 1;
R = rand(Maximum_Intensity_Value);
G = rand(Maximum_Intensity_Value);
B = rand(Maximum_Intensity_Value);

RGB_Triplets(Row,:) = [R G B];

end
%***************************************************%

% scatter(x,y,Marker_Size,RGB_Triplets,'filled');
scatter3(x,y,z,Marker_Size,RGB_Triplets);
title('Plotted Using RGB Triplets for Marker Colours');
MichaelTr7
  • 4,737
  • 2
  • 6
  • 21
  • NOTES: Error received when using gscatter3(): If g is a character array, the rows of g must be equal to the length of x, y and z OR if g is not a character array, the length of g must be equal to the length of x, y and z. Made sure all the lengths were consistent even tried transposing to see if it was dependent on vector orientation. >> – MichaelTr7 Jul 31 '20 at 06:07