按列表中点的顺序绘制颜色图 - Mathematica

发布于 2024-11-30 15:26:05 字数 287 浏览 2 评论 0 原文

我有一个三维点的列表,按时间排序。有没有办法绘制点,以便我可以获得视觉表示,其中还包括有关点在列表中发生位置的信息?我最初的想法是找到一种方法,按照绘制的顺序对点进行着色。

ListPlot3D 在点上覆盖一张纸,而不考虑它们的绘制顺序。

ListPointPlot 仅显示点,但不指示它们的绘制顺序。在这里,我正在考虑根据点在列表中出现的顺序为点着色。

与许多其他绘图函数不同,ListLinePlot 似乎没有 3D 表兄弟。

I've got a list of three dimensional points, ordered by time. Is there a way to plot the points so that I can get a visual representation that also includes information on where in the list the point occurred? My initial thought is to find a way to color the points by the order in which they were plotted.

ListPlot3D drapes a sheet over the points, with no regard to the order which they were plotted.

ListPointPlot just shows the points, but gives no indication as to the order in which they were plotted. It's here that I am thinking of coloring the points according to the order in which they appear in the list.

ListLinePlot doesn't seem to have a 3D cousin, unlike a lot of the other plotting functions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

生生漫 2024-12-07 15:26:05

您也可以执行类似

lst = RandomReal[{0, 3}, {20, 3}];
Graphics3D[{Thickness[0.005], 
  Line[lst, 
   VertexColors -> 
    Table[ColorData["BlueGreenYellow"][i], {i, 
      Rescale[Range[Length[lst]]]}]]}]

line withgradient 的操作

You could also do something like

lst = RandomReal[{0, 3}, {20, 3}];
Graphics3D[{Thickness[0.005], 
  Line[lst, 
   VertexColors -> 
    Table[ColorData["BlueGreenYellow"][i], {i, 
      Rescale[Range[Length[lst]]]}]]}]

line with gradient

无名指的心愿 2024-12-07 15:26:05

由于您没有提供示例,我通过创建 3d 自回避随机游走来弥补一些:(

Clear[saRW3d]
saRW3d[steps_]:=
    Module[{visited},
        visited[_]=False;
        NestList[
            (Function[{randMove},
                If[
                    visited[#+randMove]==False,
                    visited[#+randMove]=True;
                    #+randMove,
                    #
                ]
            ][RandomChoice[{{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}]])&,
            {0,0,0},
            steps
        ]//DeleteDuplicates
]

这有点问题,但可以完成工作;它在 3d 中产生一个随机游走,它可以避免自身,即避免重新访问同一个地方在后续步骤中)。

然后我们产生 100000 个这样的步骤,

dat = saRW3d[100000];

就像我理解你的数据点一样。然后,我们根据具体步骤来更改颜色:

datpairs = Partition[dat, 2, 1];
len = Length@datpairs;
dressPoints[pts_, lspec_] := {RGBColor[(N@First@lspec)/len, 0, 0], 
   Line@pts};
datplt = MapIndexed[dressPoints, datpairs];

这也可以像其他答案一样一次性完成

datplt=MapIndexed[
    {RGBColor[(N@First@#2)/Length@dat, 0, 0], Line@#1} &,
    Partition[dat, 2, 1]
]

,但我倾向于避免这种结构,因为我发现它们更难以阅读和修改。

最后绘制结果:

Graphics3D[datplt]

在此处输入图像描述

随着时间的推移,路径变得更红。

如果这就是您想要的东西,我可以详细说明。

编辑:很可能有更简单的方法来做到这一点...

编辑2:显示大量的点来证明这对于在 箭头不会轻易缩放。

EDIT3:添加了单行版本。

As you did not provide examples, I made up some by creating a 3d self-avoiding random walk:

Clear[saRW3d]
saRW3d[steps_]:=
    Module[{visited},
        visited[_]=False;
        NestList[
            (Function[{randMove},
                If[
                    visited[#+randMove]==False,
                    visited[#+randMove]=True;
                    #+randMove,
                    #
                ]
            ][RandomChoice[{{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}]])&,
            {0,0,0},
            steps
        ]//DeleteDuplicates
]

(this is sort of buggy but does the job; it produces a random walk in 3d which avoids itself, ie, avoids revisiting the same place in subsequent steps).

Then we produce 100000 steps like this

dat = saRW3d[100000];

this is like I understood your data points to be. We then make these change color depepnding on which step it is:

datpairs = Partition[dat, 2, 1];
len = Length@datpairs;
dressPoints[pts_, lspec_] := {RGBColor[(N@First@lspec)/len, 0, 0], 
   Line@pts};
datplt = MapIndexed[dressPoints, datpairs];

This can also be done all at once like the other answers

datplt=MapIndexed[
    {RGBColor[(N@First@#2)/Length@dat, 0, 0], Line@#1} &,
    Partition[dat, 2, 1]
]

but I tend to avoid this sort of constructions because I find them harder to read and modify.

Finally plot the result:

Graphics3D[datplt]

enter image description here

The path gets redder as time advances.

If this is the sort of thing you're after, I can elaborate.

EDIT: There might well be easier ways to do this...

EDIT2: Show a large set of points to demonstrate that this is very useful to see the qualitative trend in time in cases where arrows won't scale easily.

EDIT3: Added the one-liner version.

甜警司 2024-12-07 15:26:05

我认为海克的方法是最好的,但她让它变得过于复杂,恕我直言。我会使用:

Graphics3D[{
  Thickness[0.005], 
  Line[lst, 
   VertexColors -> 
    ColorData["SolarColors"] /@ Rescale@Range@Length@lst ]
}]

在此处输入图像描述

(acl 的数据)

I think Heike's method is best, but she made it overly complex, IMHO. I would use:

Graphics3D[{
  Thickness[0.005], 
  Line[lst, 
   VertexColors -> 
    ColorData["SolarColors"] /@ Rescale@Range@Length@lst ]
}]

enter image description here

(acl's data)

桃酥萝莉 2024-12-07 15:26:05
Graphics3D@(Arrow /@ Partition[RandomInteger[{0, 10}, {10, 3}], 2, 1])

在此处输入图像描述

Graphics3D@(Arrow /@ Partition[RandomInteger[{0, 10}, {10, 3}], 2, 1])

enter image description here

羁〃客ぐ 2024-12-07 15:26:05

至于你的最后一个问题:如果你想要一种 ListLinePlot3D 而不是 ListPointPlot 你可以简单地执行以下操作:

pointList = 
  Table[{t, Sin[t] + 5 Sin[t/10], Cos[t] + 5 Cos[t/10], 
    t + Cos[t/10]}, {t, 0, 100, .5}];

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. Point -> Line

在此处输入图像描述

当然,这样您就无法设置线条属性,因此如果您想要的话,您必须稍微更改一下规则:

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. 
       Point[a___] :> {Red, Thickness[0.02], Line[a]}

在此处输入图像描述

或使用

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. 
 Point[a___] :> {Red, Thickness[0.002], Line[a], Black, Point[a]}

在此处输入图像描述

但是,为什么不只使用 Graphics3D 和一些图形基元呢?

As to your last question: If you want to have a kind of ListLinePlot3D instead of a ListPointPlot you could simply do the following:

pointList = 
  Table[{t, Sin[t] + 5 Sin[t/10], Cos[t] + 5 Cos[t/10], 
    t + Cos[t/10]}, {t, 0, 100, .5}];

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. Point -> Line

enter image description here

Of course, in this way you can't set line properties so you have to change the rule a bit if you want that:

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. 
       Point[a___] :> {Red, Thickness[0.02], Line[a]}

enter image description here

or with

ListPointPlot3D[pointList[[All, {2, 3, 4}]]] /. 
 Point[a___] :> {Red, Thickness[0.002], Line[a], Black, Point[a]}

enter image description here

But then, why don't you use just Graphics3D and a few graphics primitives?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文