Mathematica - CSV 到多维图表

发布于 2024-11-29 18:35:01 字数 400 浏览 2 评论 0原文

我有一个 CSV 文件,其中包含 5 列和大约 2*104 行,我需要对其进行可视化。

我已经像这样导入了文件:

data = Import["res.csv", "CSV"];`

现在,我想要从中生成大量视觉效果 - 单个图上的所有 5 个维度以及各种横截面。

我的问题:

如果我想从我的数据中选择第 1、4 和 5 列并将它们提供给 ListPlot3D 我该怎么做?

并且,可以对列中的值进行分组。因此,如果我想要 ListPlot3D 列 1、2、4 和 5,但我想将列 1 和 2 分组在同一轴上,我该如何告诉 Mathematica 这样做呢?

谢谢。

I have a CSV file with 5 columns and about 2*104 rows that I need to visualise.

I've imported the file like so:

data = Import["res.csv", "CSV"];`

Now, I'm going to want to generate a lot of visuals from this - all 5 dimensions on a single plot as well as various cross sections.

My questions:

If I want to select, say columns 1, 4 and 5 from my data and feed them to ListPlot3D how would I do that?

And, values in columns can be grouped. So if I wanted to ListPlot3D colums 1, 2, 4 and 5, but I want to group columns 1 and 2 on the same axis, how would I tell Mathematica to do that?

Thanks.

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

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

发布评论

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

评论(2

寄居者 2024-12-06 18:35:01

我讨厌不同意海报,尤其是在它被接受之后,但是 Transpose 是不必要的。几乎您要求的所有内容都可以在 Part

ListPlot3D[ data[[All, {1, 4, 5}]] ]

由于矩阵在 Mathematica 中按行存储,因此可以读取 [[All, {1, 4, 5}]] [[rows, columns]]。更具体地说,All 在此表示您需要所有行,但您也可以指定特定行。另一个可能感兴趣的构造是 Span它用于指定索引组,如果您的 CSV 文件包含标题行,您可以使用

ListPlot3D[ data[[ 2 ;; , {1, 4, 5}]] ]

As 来将其从数据中剥离出来,以满足您的第二个要求,使用第 1 列和第 2 列作为 x 坐标,那么它很

ListPlot3D[ {data[[All, {2, 4, 5}]], data[[All, {1, 4, 5}]]} ]

简单你改变了如果您想删除标题行,请将 All 更改为 2;;

I hate to disagree with a fellow poster especially after it has been accepted, but the Transpose is unnecessary. Almost everything you're asking for can be done within the context of Part:

ListPlot3D[ data[[All, {1, 4, 5}]] ]

Since matrices are stored row-wise within Mathematica, [[All, {1, 4, 5}]] can be read [[rows, columns]]. More specifically, All indicates here that you want all rows, but you can specify specific rows as well. Another construct that may be of interest is Span which is used to specify groups of indices, and if your CSV file contains a header row, you can strip it from your data using

ListPlot3D[ data[[ 2 ;; , {1, 4, 5}]] ]

As to your second requirement, to use both columns 1 and 2 as the x coordinate, then it is simply

ListPlot3D[ {data[[All, {2, 4, 5}]], data[[All, {1, 4, 5}]]} ]

and you change All to 2;; if you wish to strip off the header row.

晨敛清荷 2024-12-06 18:35:01

如果我理解正确的话

ListPlot3D[Transpose[{data[[All, 1]], data[[All, 4]], data[[All, 5]]}]]

,对于多组来说,这将是:

ListPlot3D[
 {
  Transpose[{data[[All, 1]], data[[All, 3]], data[[All, 4]]}],
  Transpose[{data[[All, 2]], data[[All, 3]], data[[All, 5]]}]
  }
 ]

If I understand you correctly that would be

ListPlot3D[Transpose[{data[[All, 1]], data[[All, 4]], data[[All, 5]]}]]

and for the multiple sets:

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