plot3+color

Q: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?


A: Simplest solution is to make a scatter plot rather than a line plot:

</pre>
% 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.


Qer: Excelent solution, I would only like to add a change in the colorbar limits

caxis([ min(c) , max(c)]) % colorbar limits 

reference:

http://www.mathworks.com/matlabcentral/answers/34750-plot3-color


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值