- In this article we cover using Gnuplot with GO. This material is self-contained, but you can find further information at (http://www.gnuplot.info/).
- We provide a gnuplot script, plot1.gnu, which you can copy-paste into your working directory.
set xrange [0:10] set grid xtics ytics lt 1 lc rgb "gray80" plot "program1.dat" w l lw 3 pause -1 set terminal "svg" set output "plot1.svg" replot quit
- First we capture the output of program1.go in a file named program1.dat:
- go run program1.go > program1.dat
- Gnuplot can be run thus:
- gnuplot plot1.gnu
- A plot window appears.
- When you hit return, a svg file of the plot will be generated, which you can view and embed in another document, as required.
You can generate many different types of graphic files, such as pdf, png, gif, postscript, etc. by changing lines 5 & 6 appropriately.
For full details start gnuplot (without the plot1.gnu argument) and then enter help set terminal