Xmgrace:将多列文件中的所有列绘制为第一个函数

Xmgrace: plot all columns in multiple column file as a function of the first

我知道使用 xmgrace 如果我有一个多列文件,我可以使用命令将某一列绘制为另一列的函数(比如 3 对 1)

xmgrace -block file.dat -bxy 1:3

如果我想在同一个 window 中绘制 2vs1 和 3vs1,我将简单地使用命令

xmgrace -block file.dat -bxy 1:2 -block file.dat -bxy 1:3

但是如果文件包含大量列并且我想将所有列绘制为同一个 window 中第一个(2vs1、3vs1、4vs1 等)的函数,则变得不切实际使用这个命令。

是否有一个简单的命令来绘制文件中所有列作为第一列(2vs1、3vs1 等)的函数?

我试过了

for i in {2..n}; do xmgrace -block file.dat -bxy 1:$i; done

但是这样地块会以不同的方式出现windows...

简答:

这将为每个数据系列与第 1 列创建单独的绘图文件:

for i in {2..7}; do `gracebat -nosafe -hdevice PNG -printfile $i.png -block a.txt -bxy 1:`; done

长答案:

如果您想绘制所有列(从第 2 列到并包括第 7 列)与第 1 列 在同一轴上,您可以这样做:

for i in {2..7}; do echo -n " -block file.dat -bxy 1:$i"; done | xargs xmgrace

但由于您的问题是要求单独的地块,我们可以这样做:

for i in {2..7}; do echo -n " -block file.dat -bxy 1:$i" | xargs xmgrace; done

或这个,它给出相同的结果但更简单:

for i in {2..7}; do echo -n `xmgrace -block file.dat -bxy 1:$i`; done

然而,这不是很实用,因为各个地块一个接一个地出现,每个地块都必须关闭才能让下一个地块出现。

最好在批处理模式下将 xmgrace 设置为 运行 并为您保存每个绘图的图像。您可以使用 xmgrace 批处理文件和 gracebat 可执行文件来执行此操作。

for i in {2..7}; do `gracebat -nosafe -batch save.bfile -block a.txt -bxy 1:`; done

这会在批处理模式下使用与之前相同的数据调用 grace,但 运行s 批处理命令保存在 save.bfile 中,其中包含:

PRINT TO "out.ps"
PRINT

明显的问题是每次新的迭代都会覆盖 out.ps postscript 文件,因为输出文件的名称在我们的批处理文件中是硬编码的!所以你只能看到文件中的最后一个。幸运的是,我们每次调用 gracebat 之前都可以使用 sed 修改批处理文件!

for i in {2..7}; do `sed -e "s/outName/${i}/g" save.bfile > new.bfile`; `gracebat -nosafe -batch new.bfile -block a.txt -bxy 1:`; done

其中 save.bfile 现在包含

PRINT TO "outName.ps"
PRINT

并且字符串 outName 被替换为 $i.

你现在应该有一堆 .ps 文件,里面有你的绘图。玩弄批处理文件,以便用它做更多的事情。有关可以包括的更多命令,包括如何更改输出文件格式,请参阅 this page

或者您可以完全跳过使用批处理文件:

for i in {2..7}; do `gracebat -nosafe -hdevice PNG -printfile $i.png -block a.txt -bxy 1:`; done

如果您有参数文件,您也可以添加-param 命令来设置样式。

nxy 选项旨在执行此操作。

xmgrace -nxy file.dat

使用此选项,xmgrace 将 file.dat 的第一列读取为 x 数据,每隔一列读取为 y(i) 数据,并在同一图表上绘制 y(i) 与 x(使用默认不同的颜色)。