Use scatter3d to plot large dataset with 7 colors
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(1 个)
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
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!