Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a graph through command line with Gnuplot?

Tags:

linux

gnuplot

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?

like image 401
Aquarius_Girl Avatar asked Apr 14 '15 11:04

Aquarius_Girl


People also ask

How do you save a gnuplot graph?

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.

How do I export gnuplot?

To export Gnuplot output, you just specify a terminal which then, depending on the type of the terminal, determines the format of output file. Gnuplot supports terminals for various formats including PNG, JPG, GIF and PostScript.

How use gnuplot to plot data from a file?

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.


1 Answers

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.

like image 108
Christoph Avatar answered Oct 02 '22 22:10

Christoph