plot multiple variables with different colors
조회 수: 24 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2016년 12월 12일
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.
채택된 답변
Walter Roberson
2016년 12월 12일
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);
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!