在显示器上显示图形并将其同时保存到 gnuplot 文件中

Show graph on display and save it to file simultaneously in gnuplot

如何将图表保存到文件中并打印出来显示?我试过:

#!/usr/bin/gnuplot -p

date=system("date +%F_%T | sed 's/:/-/g'")

set term png
set output date.".png"

set term x11
set out

plot sin(x)

PS: 是否可以保存在 gnuplot window 中显示的图表?我注意到有复制到剪贴板按钮但没有保存。

如果你想将绘图同时发送到文件和交互式终端,如 x11wxt,你在更改终端后有 replot

set terminal png
set output 'file.png'

plot sin(x)

set terminal x11
set output
replot

如果您不想明确设置 x11 终端,而是使用默认终端,无论它是什么,您可以使用特殊终端 pushpop所以保存并恢复终端:

set terminal push
set terminal pngcairo
set output 'file.png'
plot sin(x)
set terminal pop
set output
replot

为了使其更透明并在将图像绘制到交互式终端后保存任何图像,您可以定义一个 gnuplot 脚本 export.gp 然后您可以 call 并将输出文件名作为参数.

export.gp脚本是

set terminal push
set terminal pngcairo
set output '[=12=]'

replot
set output
set terminal pop

然后您可以将其用作

plot sin(x)
call 'export.gp' 'test.png'

但是请注意,导出的文件和交互式window中显示的绘图会有所不同,但是如果您使用wxt作为交互式而pngcairopdfcairo作为输出终端,出现和导出的图片很相似的几率很高

在 gnuplot 5.0 中,qtwxt 终端提供了一个 "Export" 按钮,可以将 window 中显示的图像准确保存为 svg、pdf 或 png 文件。不幸的是,这个功能还不能从脚本中调用,即没有 export 命令。

中也给出了很好的答案。 对于 x11 终端,可以使用

system("xwd -id ".GPVAL_TERM_WINDOWID." | convert xwd:- screenshot.png")

也可以包成捷径

bind "Ctrl-c" 'system("xwd -id ".GPVAL_TERM_WINDOWID." | convert xwd:- png:- | xclip -sel clip -t image/png")'

所以你绘制图像

set term x11
plot sin(x)/x

然后在剧情window中按Ctrl+c。就在这里,我用 Ctrl+v:

粘贴了图像

不幸的是,它不适用于 qtwxtGPVAL_TERM_WINDOWID 关联到 x11)。他们有剪贴板按钮,但快照不可编写脚本。

只是扩展 我喜欢保留保存命令并在最后决定文件名。 所以,修改答案给了我这个

plot sin(x)
set terminal push
set terminal pngcairo
set output 'test.png'

replot
set output
set terminal pop