Plot multiple variables in different colors with scatter3
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 16 de Dic. de 2017
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 comentarios
Aulia Pramesthita
el 16 de Dic. de 2017
Image Analyst
el 16 de Dic. de 2017
Then try the scatter3 function call I gave instead of the one you've used.
Aulia Pramesthita
el 16 de Dic. de 2017
Star Strider
el 16 de Dic. de 2017
Try the code in my Answer.
Aulia Pramesthita
el 16 de Dic. de 2017
Editada: Aulia Pramesthita
el 16 de Dic. de 2017
Star Strider
el 16 de Dic. de 2017
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
el 16 de Dic. de 2017
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
el 16 de Dic. de 2017
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
el 16 de Dic. de 2017
Julien Van der Borght
el 10 de Abr. de 2018
Editada: Julien Van der Borght
el 10 de Abr. de 2018
0 votos

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!
Categorías
Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
