Plot multiple variables in different colors with scatter3
이전 댓글 표시
Hi,
I have to plot a coordinate (x,y,z).
The result of my project is 20 coordinates. I want to plot these coordinates in a 3D graph using scatter3(), or any other function, where I need to plot each coordinate in a different color.
For example:
I want to plot (x1,y1,z1) in red, (x2,y2,z2) in yellow, (x3,y3,z3) in blue.
Something like that.
But I am unable to plot these with different colors in the same graph.
Please help!
Thanks in advance!
채택된 답변
추가 답변 (2개)
Image Analyst
2017년 12월 16일
Try this:
% Create sample data.
numPoints = 100; % Will be 20 in your case.
t = linspace(0, 4*pi, 100);
x = sin(t);
y = cos(t);
z = t/50;
% Now plot each point in a different color.
% First create a list of colors - one unique color for each point.
markerColors = hsv(length(x))
% Now do the scatterplot.
scatter3(x, y, z, 50, markerColors, 'filled')
grid on

댓글 수: 9
Aulia Pramesthita
2017년 12월 16일
Image Analyst
2017년 12월 16일
Then try the scatter3 function call I gave instead of the one you've used.
Aulia Pramesthita
2017년 12월 16일
Star Strider
2017년 12월 16일
Try the code in my Answer.
Aulia Pramesthita
2017년 12월 16일
편집: Aulia Pramesthita
2017년 12월 16일
Star Strider
2017년 12월 16일
You have to specify a different color for each set of variables.
Did you run my code to see how it works? I added the scatter3 plot it produces to demonstrate that the colors are what you want for the first two sets of variables.
Image Analyst
2017년 12월 16일
Aulia, Star and I are making different assumptions. I'm assuming that all 20 (x,y,z) points/locations are in one x array, one y array, and one z array. Star is assuming that some of the 20 (say, 5 of the points) are in an array called x1, some more (say, 7 of them) are in an array called x2, and some more in an array x3, etc. So, which is it? It looks like from your line:
[x,y,z] = multilaterasi(...........
that all 20 are in single arrays.
The code I gave you, and which you asked about in your latest comment will work, assuming all 20 points are in those arrays. Each of the 20 points will have a different color. Of course, if you'd prefer, you can specify more exactly the colors you want, rather than using a built-in colormap like hsv().
Image Analyst
2017년 12월 16일
Never mind. I see you accepted Star's answer so I guess you had multiple sets of x, etc. (e.g. three vectors x1, x2, and x3) rather than just a single set (x) like I had assumed. His code will plot each set of points in the specified color. So 3 sets with one unique color for all the points in each set, like all points in set 1 in red, all points in set 2 in yellow, and all points in set 3 in blue.
Sorry I misinterpreted your original post.
Aulia Pramesthita
2017년 12월 16일
Julien Van der Borght
2018년 4월 10일
편집: Julien Van der Borght
2018년 4월 10일
0 개 추천

Hello, I have a linked question to this one. I have a vessel newtork created by Skeleton3D that I applied to my dataset. I obtain the figure that you see here with the following command: scatter3(y,x,z,3,4*s,'filled'); The colormap define the vessel diameter in the network (in micro-meter) Now, I want to emphasize the distinction between small vessel and medium one, so that the biggest one are painted in red and the other one in blue. Can you help me in this way? Thank you!
카테고리
도움말 센터 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
