This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

* sci-visualization/gnuplot
Description: Command-line driven interactive plotting program

Gnuplot's web site has a large section with many examples. It also has a very detailed handbook. What it is lacking is a very simple tutorial to get people started.

From the start, you need to be aware that gnuplot can work in three modes: a fully interactive way, by loading a plot configuration file during an interactive session, or in a non-interactive way. We are going to explore each of these three ways.

To start an interactive session, simply type the command gnuplot, after which you will have a command prompt:

$ gnuplot

        G N U P L O T
        Version 5.2 patchlevel 8 (Gentoo revision r1)    last modified 2019-12-01

        Copyright (C) 1986-1993, 1998, 2004, 2007-2019
        Thomas Williams, Colin Kelley and many others

        gnuplot home:
        faq, bugs, etc:   type "help FAQ"
        immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
gnuplot> quit

Now you are ready to operate in an interactive way, an easy and quick way to test some functions. The most important function is obviously plot. Try it:

$ gnuplot
Terminal type is now 'qt'
gnuplot> plot sin(x)/x
gnuplot> quit

After entering the command lot sin(x)/x, a window should have appeared with a picture on which the graph is plotted.

TODO: expand on interactive session, with the command replot.

But beyond making quick tests, it rapidly becomes tedious to work this way. The best is to create an input file, which you can edit and save (and even have under version control), and which you can load from within gnuplot.

Use your favorite text editor to create a file which you can name tutorial.gnuplot and save it:

$ cat tutorial.gnuplot
# Plot the function sin(x)/x:
plot sin(x)/x

The first line is obviously a comment, and the actual plotting command is on the second line.

Now you can use an interactive gnuplot session to load the file and execute its content:

$ gnuplot
Terminal type is now 'qt'
gnuplot> load "tutorial.gnuplot"
gnuplot> quit

To operate gnuplot so that an image is created straight away from your shell's command line prompt, you can set the output file in your .gnuplot file:

$ cat tutorial.gnuplot
# Plot the function sin(x)/x, and output the result into the given .png file:
set terminal png size 400,300; set output 'tutorial.png';
plot sin(x)/x

Then the following command will automatically create the image with the plot, non-interactively:
$ gnuplot tutorial.gnuplot