如何将图形保存到文件中并将其打印显示?我试过了:
#!/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)
Run Code Online (Sandbox Code Playgroud)
PS:有可能保存在gnuplot窗口中显示的图形吗?我注意到有复制到剪贴板按钮但没有保存.
如果您想要将图表发送到文件和交互式终端,x11或者wxt您replot在更改终端后拥有
set terminal png
set output 'file.png'
plot sin(x)
set terminal x11
set output
replot
Run Code Online (Sandbox Code Playgroud)
如果您不想x11明确设置终端,而是使用默认终端,无论它是什么,您都可以使用特殊终端push,pop以便保存和恢复终端:
set terminal push
set terminal pngcairo
set output 'file.png'
plot sin(x)
set terminal pop
set output
replot
Run Code Online (Sandbox Code Playgroud)
为了使其更加透明并在将其绘制到交互式终端后保存任何图像,您可以定义一个gnuplot脚本export.gp,然后您可以call将输出文件名作为参数.
该export.gp脚本
set terminal push
set terminal pngcairo
set output '$0'
replot
set output
set terminal pop
Run Code Online (Sandbox Code Playgroud)
你可以用它作为
plot sin(x)
call 'export.gp' 'test.png'
Run Code Online (Sandbox Code Playgroud)
但请注意,导出的文件和交互式窗口中显示的图形将不同,但如果您使用wxt交互式和/ pngcairo或pdfcairo输出终端,则可能性非常高,显示和导出的图像非常相似.
使用gnuplot 5.0 qt,wxt终端提供了一个"导出"按钮,可以将窗口中显示的图像精确保存为svg,pdf或png文件.不幸的是,这个功能还不能从脚本调用,即没有export命令.