Plot multiple variables in different colors with scatter3

11 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Star Strider
Star Strider am 16 Dez. 2017
Bearbeitet: Star Strider am 16 Dez. 2017
Try this:
x1 = randi(9, 5, 1);
y1 = randi(9, 5, 1);
z1 = randi(9, 5, 1);
x2 = randi(9, 5, 1);
y2 = randi(9, 5, 1);
z2 = randi(9, 5, 1);
figure(1)
scatter3(x1, y1, z1, 'r', 'filled')
hold on
scatter3(x2, y2, z2, 'y', 'filled')
hold off
grid on
legend('x_1', 'x_2')
Do the same for the rest.
  4 Kommentare
Aulia   Pramesthita
Aulia Pramesthita am 16 Dez. 2017
Bearbeitet: Aulia Pramesthita am 16 Dez. 2017
Oh I see. So, it can't work if I do it with [x,y,z]?
Star Strider
Star Strider am 16 Dez. 2017
You have to plot each vector individually with scatter3.
If your ‘x1’, ‘y1’ and ‘z1’ are column vectors stored in matrix ‘M1’ for example, as:
M1 = [x1, y1, z1];
you would plot them as:
scatter3(M1(:,1), M1(:,2), M1(:,3), 'r')
to plot ‘x1’, ‘y1’, and ‘z1’ in red.
Here the color argument 'r' tells scatter3 to plot them in red. Change that to the color you want in the other plots to plot each set in different colors, for example 'y' for yellow and 'b' for blue.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 16 Dez. 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 Kommentare
Image Analyst
Image Analyst am 16 Dez. 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
Aulia Pramesthita am 16 Dez. 2017
Yes I'm using
[x,y,z]=multilaterasi(....
The result is in one coloumn matrix, for example:
x = 20
y = 23
z = 12
x = 13
y = 22
z = 13
until I get 20 x, y, and z.
I'm trying both of your code and Star's code. I'm already trying the code that you gave. But the result are in one color. So, I'm using the code that Star gave.
If you have the shortest solution than plot each variable, I will really appreciate that.
The main of my question is actually giving identity to each coordinate (I think to distinguish it by color).
I also apologize if my question is not clear. Thankyou anyway.

Melden Sie sich an, um zu kommentieren.


Julien Van der Borght
Julien Van der Borght am 10 Apr. 2018
Bearbeitet: Julien Van der Borght am 10 Apr. 2018
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!

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by