plot multiple variables with different colors

Hi,
I have 3 variables x,y,z; each of them are double numeric arrays and their size is 1x316(all same size.
I want to plot these 3 variables in a 3D graph using scatter3(or any) function where i need to plot each variable in different colors.
Lets say:
scatter3(x,y,z,'ro','bo','go');
but i am unable to plot these with different colors in a same graph.
Please help!
Thanks in advance!

9 Commenti

I don't understand what you mean by 'each variable in different colours'. Each point in a 3d plot will take one value from each of the 3 variables.
If you want each variable a different colour then you would seem to just one a basic 3 normal scatter plots instead of a single 3d scatter plot.
Jung BC
Jung BC il 12 Dic 2016
Modificato: Jung BC il 12 Dic 2016
Hello Adam, I tried to plot all three variables with a single scatter3 function but i can't analyse
individual variable with a same color. I need to separately identify them in the same 3D axis.
Well, like I said, each point takes a value from each variable so how are you expecting the result to look with each variable its own colour in a 3d plot?
Where in three space should the combination x(1), y(1), z(1) go? What color should the result have?
Hi Walter,
When i try to plot X, Y, Z vectors in a single scatter3 function,the output plot is kind of overlapped and difficult to identify each of them with a single color.I want to visualise X, Y, and Z with 3 different colors( say r,g,b) in single xyz-axis.
I am trying to follow: https://se.mathworks.com/help/matlab/ref/scatter3.html where my output plot looks similar. I have attached two pictures here, first picture(in blue color plotting) and second is with 3 different colors which i am trying to implement. Hope it will make you understand well now.
Thanks,
<<
>>
As shown in above picture, three different colors represent values of my three vectors X, Y and Z.This i am trying to achieve in my plotting.
Adam
Adam il 12 Dic 2016
Modificato: Adam il 12 Dic 2016
The colours in that example plot are not one per variable, they are just a colour split of the 3d data into 3 different divisions, but every point still has one element from each of the x, y and z variables, just that, for example, points with a radius less than 0.5 are blue, points with between 0.5 and 0.75 are green and points between 0.75 and 1 are yellow (as an example, I don't know what the exact delineation is for that plot).
You need to work out what you want conceptually and then work out how to do it in Matlab.
Please answer my question. Give me a formula for where in 3d x(k),y(k),z(k) should go and what color the resulting point or points should be.
Jung BC
Jung BC il 12 Dic 2016
Modificato: Jung BC il 12 Dic 2016
Hi Walter,
Sorry for coming back late to you.There is no formula to apply here. Here is the scenario: x, y and z
are the vectors which contain co-ordinates of users (x->Latitude, y->Longitude and z->Altitude)
each of size 1x316. I wanted to plot these vectors altogether in
graph to see how their spatial mean centers orientation looks
like.I tried to plot all those 3 vectors in a same graph, but
most of them overlap and collide each other, so it's difficult to
identify for me whose values are latitudes, whose are longitudes
and whose are altitudes Is there any method that i can interprate these three vectors[x,y,z] i.e.(Latitude,Longitude,Altitude) by plotting in a same axis each with different colors?

Accedi per commentare.

 Risposta accettata

Your question is not making the greatest of sense to us, but I will give some possibilities:
1) Same axis as three different variables in different colors and distinct markers
axvec = 1 : length(x);
plot(axvec, x, 'ro', axvec, y, 'g^', axvec, z, 'b+');
2) Same axis as three different variables in different colors but same markers
plot( [x(:), y(:), z(:)], '*')
3) Three-dimensional scattered points, colored with RGB components proportional to the fraction of the way between minimum and maximum. Note: this technique cannot be used with more than 3 variables.
minx = min(x); miny = min(y); minz = min(z);
maxx = max(x); maxy = max(y); maxz = max(z);
xs = (x(:) - minx) ./ (maxx - minx); %scale by portion of the way through the range
ys = (y(:) - miny) ./ (maxy - miny);
zs = (z(:) - minz) ./ (maxz - minz);
cols = [xs, ys, zs]; %build a color table
pointsize = 30;
scatter3(x(:), y(:), z(:), pointsize, cols);

1 Commento

Thank you Walter!
My apology for the unclear description of my problem!
Solution (3)just works for me!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by