How to create scatter3 with jet colormap

102 ビュー (過去 30 日間)
Karolina
Karolina 2013 年 11 月 8 日
コメント済み: Karolina 2013 年 11 月 12 日
Hello,
I have a data with X, Y, Z coordinates and I would like to apply coloring in scatter3 (from blue to red for my Z attribute - which represent height above sea level). I am trying to do scatter3 with "Jet" color map, but I do not know how to assign "Jet" color scale to my Z attribute. I achieved an error, that my G attribute is not specified. I will be grateful for some suggestion how to specify my G attribute. My code is below.
Karolina
X=test_matlab(:,1);
Y=test_matlab(:,2);
Z=test_matlab(:,3);
G=jet(Z)
scatter3(X,Y,Z,20,G,'filled')
xlabel('X Coordinate');
ylabel('Y Coordinate');
zlabel('Height above sea level');

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 11 月 8 日
編集済み: Sean de Wolski 2013 年 11 月 8 日
%Some data
[xx, yy] = meshgrid(1:100);
zz = cos(xx).*sin(yy).^2;
% Scatter3, size 5, color based on zz
scatter3(xx(:),yy(:),zz(:),5,zz(:));
% colomap and bar
colormap(jet);
colorbar;
scatter3 (or scatter) takes in an argument C that allows you to color based on this input. For your case this is likely Z. What you're doing right now is passing in the colormap values which is unnecessary because the colormap is a property of the figure not the scatter plot.
doc scatter
  1 件のコメント
Karolina
Karolina 2013 年 11 月 12 日
Thank you for the answer for my question! Below I attached final commands, if somebody would like to use it:
load('test_matlab.csv'); %colorize by Z coordinate X=test_matlab(:,1); Y=test_matlab(:,2); Z=test_matlab(:,3); C=Z scatter3(X(:),Y(:),Z(:),5,C(:),'.'); colormap(jet); colorbar; xlabel('X Coordinate'); ylabel('Y Coordinate'); zlabel('Height above sea level');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePurple についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by