plot3基于值的线颜色 [英] plot3 line color based on value

查看:1347
本文介绍了plot3基于值的线颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组包含3d笛卡尔点(x,y,z)和时间戳的数据。

I have a set of data that contains 3d Cartesian points (x, y, z) and a time stamp.

我想将此数据绘制为连接的线在3d空间中,线颜色基于时间戳值改变。

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?

推荐答案

考虑下面的一个3D点沿着螺旋形路径随时间移动的示例:

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)

现在,如果你想绘制一条多色的线,那么这个朴素的解决方案就是写一个for循环,单独的线,每个具有不同的颜色。这是因为单个线对象只能有一种颜色。

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)) )

结果:

这篇关于plot3基于值的线颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆