Use scatter3d to plot large dataset with 7 colors

조회 수: 1 (최근 30일)
B de Bruin
B de Bruin 2020년 8월 15일
댓글: Star Strider 2020년 8월 16일
I have a dataset of about 1500 observations with three numerical variables X, Y, Z, plus a variable C assigning one of seven colors to each observation. How do I use scatter3d to get the corresponding graph (where each observation gets the color as specified in C)? I find many examples/posts for scatter3d on mathworks, but they all involve just a slightly different problem.

채택된 답변

Star Strider
Star Strider 2020년 8월 15일
It may be necessary to describe the problem in greater detail. The scatter3 documentation implies that it would be appropriate for the problem.
If ‘X’, ‘Y’, ‘Z’ and ‘C’ are matrices, it would be necessary to convert them to vectors to use scatter3:
figure
scatter3(X(:), Y(:), Z(:), [], C(:))
I sometimes find it preferable to use stem3, since it establishes the locations of the data, then hold, then scatter3 to add the colours.
  댓글 수: 8
B de Bruin
B de Bruin 2020년 8월 16일
Thanks again!
Star Strider
Star Strider 2020년 8월 16일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ferheen Ayaz
Ferheen Ayaz 2020년 8월 15일
I suggest to use surf or mesh instead of scatter 3d and colorbar for setting seven colors.
surf(X,Y,Z);
h=colorbar('Ticks',C);
  댓글 수: 3
Ferheen Ayaz
Ferheen Ayaz 2020년 8월 15일
I am not sure if it can be applied to your problem, but I have used the following before using surf
[X,Y,Z] = meshgrid(x,y,z)
B de Bruin
B de Bruin 2020년 8월 15일
Might the data be too large for this? It doesn't halt.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by