If you need a simple command-line tool for making charts, Gnuplot is a great choice.

Table of Contents

Starting Gnuplot

You can run a script file (gnuplot script.gnu) or use the interactive mode. For this tutorial, I am going to use the interactive mode.

$ gnuplot

	G N U P L O T
	Version 5.4 patchlevel 2    last modified 2021-06-01 

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

	gnuplot home:     http://www.gnuplot.info
	faq, bugs, etc:   type "help FAQ"
	immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
gnuplot> 

Close Gnuplot by typing quit.

Set terminal

You can set how to output the plots with set terminal. By default, it will show a GUI window. Gnuplot default terminal

# Show plots directly in the terminal window
set terminal dumb
# Output as a PNG, you can define a width in pixels
set terminal png size 600

In case you want to output plots as files, you must specify the file name.

set output 'image.png'

Set datafile separator

Define what character separates the fields with set datafile separator '<character>'.

set datafile separator ','

Define data format

Set data from an axis to be dates by typing set xdata|ydata time.

set xdata time

Then, define the date-time format of the data with set timefmt '<format>'.

set timefmt '%Y-%m-%d %H:%M:%S'

Create a plot

Finally, create a plot with plot '<file>' using <col-number-x>:<col-number-y> with dots|lines|points.

plot 'test.csv' using 1:3 with points
  • You can specify more options like title "myplot" or smooth bezier (check gnuplot help).

More options

Set title based on file data

Following command causes the first entry in each column of input data to be interpreted as a text string and used as a title for the corresponding plot.

set key autotitle columnheader

Set axis ranges

Set minimum and maximum value on every axis with set xrange|yrange [min:max]. You can use * to set autoscaling in one of the range limits.

set yrange [0:200]
set yrange [*:1200]

Add axis labels

Add labels for every axis with set xlabel|ylabel 'mylabel'

set xlabel 'Year'

Add grid

set grid

Unset

Options defined with set can be returned to their default state by the corresponding unset command.

unset xrange

Get help

You can type help inside Gnuplot to get more info. Inside help, press Enter to go through a help page. At the end, it will show you a list of subpages: you can type the name of the subpage or press Enter again to go to the parent page or exit.

You can also check official documentation (PDF).