Clear Filters
Clear Filters

plot multiple variables with different colors

47 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 12 Dec 2016
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 on 12 Dec 2016
Edited: Jung BC on 12 Dec 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?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Dec 2016
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 Comment
Jung BC
Jung BC on 12 Dec 2016
Thank you Walter!
My apology for the unclear description of my problem!
Solution (3)just works for me!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!