If you want to send graphics both to a file and to an interactive terminal, for example x11 or wxt , you have replot after you change the terminal
set terminal png set output 'file.png' plot sin(x) set terminal x11 set output replot
If you do not want to explicitly install the x11 terminal, but use the default terminal, whatever it is, you can use special push and pop terminals to save and restore the terminal:
set terminal push set terminal pngcairo set output 'file.png' plot sin(x) set terminal pop set output replot
To make it more transparent and save any image after you have built it on the interactive terminal, you can define a gnuplot script export.gp , which you can then call and specify the name of the output file as a parameter.
export.gp script is
set terminal push set terminal pngcairo set output '$0' replot set output set terminal pop
which can then be used as
plot sin(x) call 'export.gp' 'test.png'
Please note that the exported file and the graph shown in the interactive window will be different, but if you use wxt as interactive and pngcairo or pdfcairo as output terminals, the probability will be quite high that the displayed and exported images are very similar.
With gnuplot 5.0, the qt and wxt offer an βExportβ button to accurately save the image shown in the window as svg, pdf or png files. Unfortunately, this function cannot yet be called from a script, i.e. There is no export command.
source share