Mathematica - CSV 到多维图表
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我讨厌不同意海报,尤其是在它被接受之后,但是 Transpose 是不必要的。几乎您要求的所有内容都可以在
Part
:
由于矩阵在 Mathematica 中按行存储,因此可以读取
[[All, {1, 4, 5}]]
[[rows, columns]]
。更具体地说,All
在此表示您需要所有行,但您也可以指定特定行。另一个可能感兴趣的构造是Span
它用于指定索引组,如果您的 CSV 文件包含标题行,您可以使用As 来将其从数据中剥离出来,以满足您的第二个要求,使用第 1 列和第 2 列作为 x 坐标,那么它很
简单你改变了如果您想删除标题行,请将
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 ofPart
: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 isSpan
which is used to specify groups of indices, and if your CSV file contains a header row, you can strip it from your data usingAs to your second requirement, to use both columns 1 and 2 as the x coordinate, then it is simply
and you change
All
to2;;
if you wish to strip off the header row.如果我理解正确的话
,对于多组来说,这将是:
If I understand you correctly that would be
and for the multiple sets: