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?
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.