I have a set of data that contains 3d Cartesian points (x, y, z) and a time stamp.
I would like to plot this data as a connected line in 3d space with the line colour changing based on the time stamp value.
Effectively i want to show the time difference in a colorbar.
Does anyone know of a way to do this?
Consider the following example of a 3D point moving along a helix-shaped path over time:
%# data
t = linspace(0,8*pi,200);
x = 20*t; y = cos(t); z = sin(t);
%# plot 3D line
plot3(x,y,z)
axis tight, grid on, view(35,40)
Now if you want to draw a multi-colored line, the naive solution would be to write a for-loop, drawing each small segment as a separate line, each having a different color. This is because a single line object can only have one color.
A better approach is to use a surface graphics object:
c = 1:numel(t); %# colors
h = surface([x(:), x(:)], [y(:), y(:)], [z(:), z(:)], ...
[c(:), c(:)], 'EdgeColor','flat', 'FaceColor','none');
colormap( jet(numel(t)) )
The result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With