problem with colorbar in using scatter3

Hi. I have a table called "damage" with four collumns "wind", "I", "derate", "Index4". I am using the following code to plot "Index4" vs. "wind", "I" and "derate":
s = scatter3(damage,'wind','I','derate','filled','ColorVariable','Index4'); s.SizeData = 100;colorbar
but I get the following error:
Error using scatter3 (line 57)
Color must be one RGB triplet, an m-by-3 matrix of RGB triplets with one color per scatter point, or an m-by-1 vector with one
value per scatter point.
Any feedback is very much appreciated.

2 comentarios

Joe Vinciguerra
Joe Vinciguerra el 6 de Sept. de 2022
Please attach a .mat file of your table
.mat file is attached now

Iniciar sesión para comentar.

 Respuesta aceptada

First, the error is not related to colorbar. It is an error occurring with scatter3, specifically the format of your ColorVariable.
I can duplicate the error by making Index4 anything but what is expected (indicated in the error message). The fix is to make Index4 one of the accepted inputs (described here: https://www.mathworks.com/help/matlab/ref/scatter3.html#mw_0ec595ed-40a4-4191-be63-534236f0fb9e)
% How I can recreate the error message: Index4 is not mx3, 1x3, nor mx1
wind = [30 40 50]';
I = [1 2 3]';
derate = [5 6 5]';
Index4 = [1 3 7;2 5 9]';
damage = table(wind,I,derate,Index4)
damage = 3×4 table
wind I derate Index4 ____ _ ______ ______ 30 1 5 1 2 40 2 6 3 5 50 3 5 7 9
s = scatter3(damage,'wind','I','derate','filled','ColorVariable','Index4');
Error using scatter3
Color must be one RGB triplet, an m-by-3 matrix of RGB triplets with one color per scatter point, or an m-by-1 vector with one value per scatter point.
s.SizeData = 100;
colorbar

3 comentarios

These four variables are four time series of the same length. I plan to picturize it by a 4D plot. I use colormap to show the forth diemension. Yeah the error looks to be with the format of ColorVariable but not sure about a proper way to define this variable. My problem looks very similar to what here
That's the same example I linked to, so glad we are agreed.
It looks like the issue is you have some complex numbers in Index4. Consider using the magnitude of your values to specify color. If the values should not be complex, check how Index4 is calculated.
load matlabFarid.mat
damage.Index4 = abs(damage.Index4)
damage = 1000×4 table
wind I derate Index4 ____ _ ______ __________ 4 0 0 3.2381e-06 4 0 10 3.806e-06 4 0 20 3.806e-06 4 0 30 3.806e-06 4 0 40 3.8062e-06 4 0 50 3.8057e-06 4 0 60 3.8062e-06 4 0 70 3.8057e-06 4 0 80 3.8059e-06 4 0 90 3.8059e-06 4 0 100 3.806e-06 4 4 0 3.2384e-06 4 4 10 3.7961e-06 4 4 20 3.7951e-06 4 4 30 3.797e-06 4 4 40 3.7961e-06
s = scatter3(damage,'wind','I','derate','filled','ColorVariable','Index4');
s.SizeData = 100;
colorbar
You are right. Thanks so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by