I'm writing a batch file which will also generate a gnuplot graph from a dat file.
I wish to call gnuplot from the command line, using the gnuplot "gnu" script I have written, and save the output graph to an image.
Something like:
gnuplot.exe script.gnu > image.png
Any ideas?
There are two ways to save your work in gnuplot: you can save the gnuplot commands used to generate a plot, so that you can regenerate the plot at a later time. Or you can export the graph to a file in a standard graphics file format, so that you can print it or include it in web pages, documents, or presentations.
gnuplot> set term png (will produce . png output) gnuplot> set output "printme. png" (output to any filename. png you want) gnuplot> replot gnuplot> set term x11 You can view it with some viewer, or on a browser, or print it... or import it in PowerPoint or whatever you want to do with it.
To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.
Plots panel –> Export –> Save as Image or Save as PDF Specify files to save your image using a function such as jpeg(), png(), svg() or pdf(). Additional argument indicating the width and the height of the image can be also used.
You don't have to redirect the output from gnuplot into an image file; you can set that inside the gnuplot script itself:
set terminal png
set output 'image.png'
If you want to have a variable output name, one simple way to do that in bash is to wrap the gnuplot commands thus:
#!/bin/bash
echo "set terminal png
set output '$1'
plot 'data.dat'" | gnuplot
This way you can run the bash script with an argument for the output file name:
./plotscript.sh image.png
Simply putting the following line will make gnuplot to return png-format bytecode. Thus, you can redirect the output to a png-file.
set terminal png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With