problem with colorbar in using scatter3
조회 수: 8 (최근 30일)
이전 댓글 표시
Farid Khazaeli Moghadam
2022년 9월 6일
댓글: Farid Khazaeli Moghadam
2022년 9월 7일
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
채택된 답변
Cris LaPierre
2022년 9월 6일
First, the error is not related to colorbar. It is an error occurring with scatter3, specifically the format of your ColorVariable.
It looks like you found this example in the doc: https://www.mathworks.com/help/matlab/ref/scatter3.html#mw_980777c0-abb7-4053-b084-6da6cc75c25a
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)
s = scatter3(damage,'wind','I','derate','filled','ColorVariable','Index4');
s.SizeData = 100;
colorbar
댓글 수: 3
Cris LaPierre
2022년 9월 6일
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)
s = scatter3(damage,'wind','I','derate','filled','ColorVariable','Index4');
s.SizeData = 100;
colorbar
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

