Show graph on display and save it to file at the same time in gnuplot

How to save a graph in a file and print it for display? I tried:

#!/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: Is it possible to save the graph that is displayed in the gnuplot window? I noticed that there is a copy button to the clipboard, but no save.

+6
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/987468/


All Articles