plot3+color

6 ビュー (過去 30 日間)
Thijs
Thijs 2012 年 4 月 6 日
コメント済み: Guðmundur 2013 年 11 月 29 日
I have a [N,4] data set which I want to visualize as 3d line representing the fourth column as a color. Any ideas on how to do this?

回答 (1 件)

Matt Tearle
Matt Tearle 2012 年 4 月 13 日
Sorry, just noticed this hasn't been answered for some reason. Simplest solution is to make a scatter plot rather than a line plot:
% Make some fake data
x = linspace(0,1); % x = data(:,1);
y = cos(10*x); % y = data(:,2);
z = sin(15*x); % z = data(:,3);
c = x+y-z; % c = data(:,4);
figure
scatter3(x,y,z,2,c)
colorbar
If, however, you really need lines, you probably need to brute-force it.
figure
cmap = colormap;
% change c into an index into the colormap
% min(c) -> 1, max(c) -> number of colors
c = round(1+(size(cmap,1)-1)*(c - min(c))/(max(c)-min(c)));
% make a blank plot
plot3(x,y,z,'linestyle','none')
% add line segments
for k = 1:(length(x)-1)
line(x(k:k+1),y(k:k+1),z(k:k+1),'color',cmap(c(k),:))
end
colorbar
Here I'm using the default colormap for the figure to define the colors. You can specify colors however you want, as long as you have a way to index into them.
  1 件のコメント
Guðmundur
Guðmundur 2013 年 11 月 29 日
Excelent solution, I would only like to add a change in the colorbar limits
caxis([ min(c) , max(c)]) % colorbar limits

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by