Gnuplot: making plots with the Terminal
If you need a simple command-line tool for making charts, Gnuplot is a great choice.
Table of Contents
- Starting Gnuplot
- Set terminal
- Set datafile separator
- Define data format
- Create a plot
- More options
- Get help
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
# 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
smooth bezier(check gnuplot help).
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'
Options defined with
set can be returned to their default state by the corresponding
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).
In Debian/Ubuntu systems, you can use
dpkg-reconfigureto reconfigure an installed package using intuitive dialogs. I will show you how to use this command to change some system settings.
If you have a scanned PDF and you want to be able to search and copy text from it, in this tutorial I will show you how to do it.
If you want to do X11 forwarding from your container to your host, you can type these simple commands.
If you don’t have a Graphical User Interface (GUI) on your Linux device, or you need a simple text-based web browser, I will show you a couple of great programs.
A comprehensive list of Linux-related websites sorted by categories.