Plot3 line color based on value

I have a dataset containing 3d Cartesian points (x, y, z) and a timestamp.

I would like to construct this data as a connected line in 3d space with a color change of the line based on the value of the timestamp.

In fact, I want to show the time difference in the color bar.

Does anyone know how to do this?

+6
source share
1 answer

Consider the following example of a three-dimensional point moving in a spiral 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-color line, a naive solution would be to write a for-loop loop, drawing each small segment as a separate line, each of which has a different color. This is because an object with one line can have only one color.

It is better to use a surface graphic object:

 c = 1:numel(t); %# colors h = surface([x(:), x(:)], [y(:), y(:)], [z(:), z(:)], ... [c(:), c(:)], 'EdgeColor','flat', 'FaceColor','none'); colormap( jet(numel(t)) ) 

Result:

screenshot

+9
source

Source: https://habr.com/ru/post/922323/


All Articles