【问题标题】:why gnuplot does not plot after fit?为什么gnuplot在拟合后不绘图?
【发布时间】:2014-05-29 13:28:28
【问题描述】:

我正在尝试拟合一条线性曲线,然后用拟合线绘制图形。但是,以下内容不起作用,因为 gnuplot 会生成 0 kbyte .png 输出。

set t push
set term png
fit f(x) "NET_OUTPUT.dat" u 1:2 via a,b 
plot "NET_OUTPUT.dat" using 1:2 with points, f(x) 
unset output
set term pop

如果不包括拟合线,我可以毫无问题地绘制。 我怀疑问题是fit.log文件被写入,而gnuplot没有完成输出文件的写入。

有人知道问题出在哪里吗? 非常感谢!

【问题讨论】:

  • 如果将set output 命令放在set term png 之后会发生什么?如果您提供有关您使用的 gnuplot 版本、操作系统等的信息,将会很有帮助。就目前而言,代码不是一个最小的工作示例——您能否提供一个小版本的数据文件,我们可以尝试使用它重现问题?
  • 你也没有设置任何输出文件。
  • 他可能会将标准输出重定向到一个文件,在这种情况下,它可能是系统特定的问题。
  • 你是如何设置f(x)的?您是否设置了输出文件或正在重定向输出?你真的需要 push/pop,如果需要,为什么?
  • 感谢 cmets。我在 Windows7 上使用 gp424win32 版本。实际上,我有 net_sug.gp 文件: GNUTERM = "win" f(x)=a*x+b a=1 b=0 ti = sprintf("%.2fx+%.2f", a, b) fit f(x) "NET_OUTPUT_ketp_bin_3600_mask2.dat" u 1:2 via a,b plot "NET_OUTPUT_egyp_ketp_3600_mask_ketp_n_q.dat" using 1:2 with points, f(x) t ti unset output" 我把这个表格称为另一个文件:set t push set term png set output "$0" load "net_sug.gp" set output set term pop

标签: plot output gnuplot


【解决方案1】:

对于绘制到 png 时的 gnuplot,我通常会创建如下脚本:

#!/usr/bin/gnuplot

set term png
set output "out.png"

f(x) = a*x + b
fit f(x) "data.dat" u 1:2 via a,b

plot "data.dat" u 1:2, f(x)

并使用./plot.gnu 调用它,或者我创建一个脚本,例如:

#!/usr/bin/gnuplot

set term png

f(x) = a*x + b
fit f(x) "data.dat" u 1:2 via a,b

plot "data.dat" u 1:2, f(x)

并使用./plot.gnu > out.png 调用它。

第一种方式要求 gnuplot 将 png 写入指定的输出文件。第二个要求 gnuplot 生成 png,但没有设置位置(因此它被转储到标准输出),在这种情况下,我将标准输出(在 bash 中使用>)重定向到我的 png 文件。

您也可以在命令行中使用gnuplot plot.gnugnuplot plot.gnu > out.png 将脚本传递到gnuplot,在这种情况下,以# 开头的行将作为cmets 被忽略。

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多