gnuplot:第1行:命令无效

时间:2012-06-07 18:18:09

标签: python command cygwin gnuplot

你好所有可爱的人在stackoverflow上,

我正在尝试使用gnuplot绘制数据。我首先阅读一个表并提取我想要的数据。我将此数据写入.dat文件。截至目前,我只是试图通过命令行绘制它,但会添加必要的代码,以便在python脚本工作后将其绘制出来。

我创建.dat文件的代码 -

#!/usr/bin/python

file = open("test_m.rdb")
table = open('table.dat', 'w+')

trash = file.readline()

trash = file.readline()

data = file.readline()
i = data.split()
flux = i[2]
observed = i[4]
table.write(flux + " " + observed,)

while 1:
    line = file.readline()
    i = line.split()
    try:
        flux = i[2]
        observed = i[4]
    except IndexError:
        break
    table.write("\n" + flux + " " + observed)
    table.close()

我试图在cygwin中使用的命令和错误 -

gnuplot plot table.dat

0.058 2
^
"table.dat", line 1: invalid command

提前谢谢你。我感谢您提出的任何建议。

1 个答案:

答案 0 :(得分:3)

你可能想要:

gnuplot --persist -e 'plot "table.dat" u 1:2'

使用您的命令,gnuplot正在寻找在名为“plot”的文件中运行的命令,然后在名为“table.dat”的文件中运行。 'table.dat'没有要运行的命令,它有数据要绘制。使用'-e'与将单引号中的内容放入临时文件(称为temp.gp)然后执行gnuplot temp.gp是一回事。 --persist使得情节保持在你的屏幕上(你会想要,因为我怀疑你将它保存到文件中)。要了解如何将其保存到文件,请在gnuplot内执行:help set termhelp set output以及set term

编辑

我对cygwin了解不多,所以我不知道默认终端是什么(或者启用了什么终端)。

要尝试的一些事项:

gnuplot -e 'plot "table.dat" u 1:2; pause -1'  #this should leave your plot open until you hit return

将命令放在文件中

#tmp.gp
set term postscript enh color
set output "tmp.ps"
plot "table.dat" u 1:2

现在运行它:

gnuplot tmp.gp

然后使用你查看postcripts的任何工具打开postscript - 我经常使用gv,但我不知道cygwin上有什么。

gv tmp.ps &
相关问题