How to save a graph through command line with Gnuplot?

Aquarius_Girl picture Aquarius_Girl · Apr 14, 2015 · Viewed 27k times · Source

gnuplot -p -e "plot [-4:4] exp(-x**2 / 2); set terminal png size 400,300; set output 'xyz.png'"

That's what I have tried. It does create the png, but corrupted.

Where am I going wrong?

Answer

Christoph picture Christoph · Apr 14, 2015

You must set the terminal and the output file name before plotting:

gnuplot -e "set terminal png size 400,300; set output 'xyz.png'; plot [-4:4] exp(-x**2 / 2)"

In that case you also don't need the persist flag.