有什么方法可以在命令行动态绘制来自 GNUPLOT 的图形吗?

Is there any way to dynamically plot graphs from GNUPLOT at the command line?

我一直在使用 gnuplot,现在我想要一个程序从命令行进入 运行 gnuplot 并直接绘制图形。 类似于:

gnuplot>plot sin(x)

不过我总是要运行 gnuplot 然后写绘图命令。

如手册页所述:

-e "command list" executes the requested commands before loading the next input file.

所以在你的具体情况下,在我看来你所追求的是:

gnuplot -e "plot sin(x)"

您还可以 运行 Gnuplot 作为 shell 的协同进程,例如bash:

coproc gnuplot

现在您可以通过在 ${COPROC[1]} 中找到的文件描述符向 Gnuplot 进程发送命令,例如:

echo 'plot sin(x)' >&${COPROC[1]}

或者如果您将文件描述符值保存在 p 中:

p=${COPROC[1]}
echo 'plot sin(x)' >&$p

有关其他 shell 和替代符号,请参阅 Stephane's answer