gnuplot:行1:无效命令

2024-09-26 22:46:06 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,斯塔克弗洛夫大街上的可爱的人们

我试图用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

提前谢谢你。我很感激你能给我任何建议。


Tags: 文件数据代码datareadlinelinetable绘制
1条回答
网友
1楼 · 发布于 2024-09-26 22:46:06

你可能想要:

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

使用您的命令,gnuplot正在寻找在名为“plot”的文件中运行的命令,然后在名为“table.dat”的文件中运行table.dat'没有要运行的命令,它有要绘制的数据。使用'-e'与将单引号中的内容放入临时文件(称为temp.gp)中,然后执行gnuplot temp.gp相同的操作。这个--persist使它保持在你的屏幕上(这是你想要的,因为我怀疑你把它保存到一个文件中)。要了解如何将其保存到文件中,请在gnuplot do中:help set termhelp set outputset 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

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

gv tmp.ps &

相关问题 更多 >

    热门问题