Gnuplot:如何跳过矩阵输入中的列进行绘图?
Gnuplot: How do I skip columns in matrix input to plot?
我有以下形式的数据文件:
unimportant1 unimportant2 unimportant3 matrixdata[i]
1e4 2e5 3e2 1 2 3 4 5
2e3 1e1 7e3 5 4 3 2 1
... ... ... ...
2e3 1e4 4e2 4 4 4 4 4
所以它的第一行有第 header 列(这里是 "unimportant1" 到 "unimportant3")。我希望 gnuplot 忽略前三个不重要的列列,因此数据条目采用指数表示法。我希望 gnuplot 将矩阵数据绘制为矩阵。就好像我是这样做的:
#!/usr/bin/gnuplot -p
plot '-' matrix with image
1 2 3 4 5
5 4 3 2 1
...
4 4 4 4 4
e
如何让 gnuplot 忽略前三列和 header 行并将其余列绘制为 矩阵图像 ?为了兼容性,我更喜欢 gnuplot built-in 来做到这一点,但我可以编写一个 shell 脚本并使用 `plot '< ...' 语法预处理数据文件。
编辑:所以neuhaus' 差不多解决了。我唯一缺少的是,如何忽略带有文本 header 数据的第一行(行)。每个人似乎都期望数字数据,因此整个图都失败了,因为它不是矩阵。我不想注释掉第一行,因为我将不重要的数据集用于其他二维图,而这些二维图又使用 header 数据。
那么如何跳过已经使用 every
跳过列的矩阵图中的一行?
我不熟悉矩阵图,但我得到了一些示例数据并且
plot 'matrix.dat' matrix every ::3 with image
似乎可以解决问题。
使用matrix
时,gnuplot 必须先解析数据文件,然后才能跳过行和列。现在,您的第一行评估为四个无效数字,第二行有 8 个数字,我得到一个错误 Matrix does not represent a grid
.
如果您不想注释掉第一行或使用 < tail -n +2 matrix.dat
等外部工具跳过它,则可以将其更改为包含一些虚拟字符串,例如
unimportant1 unimportant2 unimportant3 matrixdata[i] B C D E
1e4 2e5 3e2 1 2 3 4 5
2e3 1e1 7e3 5 4 3 2 1
... ... ... ...
2e3 1e4 4e2 4 4 4 4 4
现在您的第一行与其他行的条目一样多,您可以使用
绘制此文件
plot 'test.txt' matrix every ::3:1 with image
这还是给你一个warning: matrix contains missing or undefined values
,不过你不用管了。
您可能会使用 shell 命令,例如,以下命令会跳过文件的前六行:
plot '<tail -n +7 terrain0.dem' matrix with image
我有以下形式的数据文件:
unimportant1 unimportant2 unimportant3 matrixdata[i] 1e4 2e5 3e2 1 2 3 4 5 2e3 1e1 7e3 5 4 3 2 1 ... ... ... ... 2e3 1e4 4e2 4 4 4 4 4
所以它的第一行有第 header 列(这里是 "unimportant1" 到 "unimportant3")。我希望 gnuplot 忽略前三个不重要的列列,因此数据条目采用指数表示法。我希望 gnuplot 将矩阵数据绘制为矩阵。就好像我是这样做的:
#!/usr/bin/gnuplot -p
plot '-' matrix with image
1 2 3 4 5
5 4 3 2 1
...
4 4 4 4 4
e
如何让 gnuplot 忽略前三列和 header 行并将其余列绘制为 矩阵图像 ?为了兼容性,我更喜欢 gnuplot built-in 来做到这一点,但我可以编写一个 shell 脚本并使用 `plot '< ...' 语法预处理数据文件。
编辑:所以neuhaus'
那么如何跳过已经使用 every
跳过列的矩阵图中的一行?
我不熟悉矩阵图,但我得到了一些示例数据并且
plot 'matrix.dat' matrix every ::3 with image
似乎可以解决问题。
使用matrix
时,gnuplot 必须先解析数据文件,然后才能跳过行和列。现在,您的第一行评估为四个无效数字,第二行有 8 个数字,我得到一个错误 Matrix does not represent a grid
.
如果您不想注释掉第一行或使用 < tail -n +2 matrix.dat
等外部工具跳过它,则可以将其更改为包含一些虚拟字符串,例如
unimportant1 unimportant2 unimportant3 matrixdata[i] B C D E
1e4 2e5 3e2 1 2 3 4 5
2e3 1e1 7e3 5 4 3 2 1
... ... ... ...
2e3 1e4 4e2 4 4 4 4 4
现在您的第一行与其他行的条目一样多,您可以使用
绘制此文件plot 'test.txt' matrix every ::3:1 with image
这还是给你一个warning: matrix contains missing or undefined values
,不过你不用管了。
您可能会使用 shell 命令,例如,以下命令会跳过文件的前六行:
plot '<tail -n +7 terrain0.dem' matrix with image