【问题标题】:gnuplot: line 1: invalid commandgnuplot:第 1 行:无效命令
【发布时间】:2012-06-07 18:18:09
【问题描述】:

大家好,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

提前谢谢你。感谢您提供任何建议。

【问题讨论】:

    标签: python command cygwin gnuplot


    【解决方案1】:

    你可能想要:

    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 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 &
    

    【讨论】:

    • 谢谢,当我尝试该命令时,cygwin 给了我这个错误 - 0 [main] gnuplot 7176 exception::handle: Exception: STATUS_ACCESS_VIOLATION 4903 [main] gnuplot 7176 open_stackdumpfile: 将堆栈跟踪转储到 gnuplot.exe .stackdump gnuplot: 无法打开显示'' gnuplot: X11 aborted.
    • 再次感谢您的帮助。这两个选项都给了我同样的错误“无法打开显示”。是否有可能某些东西没有打开显示所需的权限?
    • 使用第二个选项,您是否在当前目录中获得了一个名为“tmp.ps”的文件? (ls 会告诉你它是否存在)。如果你有gv,那么如果你的cygwin环境没有正确配置为使用X11,如果文件存在,它会抱怨与gnuplot相同是合理的(你需要谷歌搜索如何修复那个) -- 我不知道)。
    • 哦,哇,是的,那个文件就在那里。这就是我想要的图表!非常感谢!
    • 没问题。如果这个答案有用,您可以随时接受:meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 2021-07-03
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 2020-08-04
    相关资源
    最近更新 更多