Gnuplot: Frequently Asked Questions

Inofficial Gnuplot FAQ

This is an inofficial gnuplot FAQ (yes, its my personal one).


Where can I find the official gnuplot FAQ?

Look here. – Note that there are also some not so Frequently Asked Questions.

How can I make a gnuplot script an executable file?

Add the shebang to the first line of your script 1)

#!/usr/bin/env gnuplot
plot sin(x) with lines

How do I change the datafield separator?

E.g. to read in csv (comma-separated value) files written by spreadsheet programs.

set datafile separator ","

How do I change decimal separator?

set decimalsign ','                     # set separator to ','
#set decimalsign locale                 # get separator from system locale settings
#set decimalsign locale "en_GB.utf8"    # set separator to '.' by overriding system locale
#set decimalsign locale "de_DE.utf8"    # set separator to ',' by overriding system locale

How do I export a plot as list of ASCII-data samples?

set table
#set terminal table  # some releases of gnuplot need the keyword 'terminal'
set output "temp(u).dat"
set samples 1024
plot [0:1023] f(x*4.8/1024)

How to change plot device/output media?

set terminal emf           # Windows Enhanced Meta File
set output "filename.emf"
replot                     # plot again but utilize the new terminal
set term pop               # return to primary terminal

How do I change output format of numbers?

set format "%.1f"  # output float numbers with one digit after decimal separator

Note that format can be limited to axes, e.g.

set format y "%.1f"

How do I change background color of screen and/or graph?

# define screen background color
set object rectangle from screen 0,0 to screen 1,1 fillstyle border fillcolor '#deebf7' behind
 
# define graph background color
set object rectangle from graph 0,0 to graph 1,1 fillstyle border fillcolor 'white' behind

How to change linestyle (e.g. line width) for a set of lines?

set for [i=1:8] style line i linewidth 3

How to set line colors to MATLAB default colors?

:Y_FIXME:

# New default Matlab line colors, introduced together with parula (2014b)
set style line 1 lc rgb '#0072bd' # blue
set style line 2 lc rgb '#d95319' # orange
set style line 3 lc rgb '#edb120' # yellow
set style line 4 lc rgb '#7e2f8e' # purple
set style line 5 lc rgb '#77ac30' # green
set style line 6 lc rgb '#4dbeee' # light-blue
set style line 7 lc rgb '#a2142f' # red

How can I add a watermark?

# Urheberkennzeichnung
watermark = "`whoami`".'\@'."`hostname`, `date`"
set label watermark at screen 0.01,0.02 font ',6' tc rgb 'gray'
#set bmargin 3.75

How to plot multiple y-axes?

Is there an overview about the predefined gnuplot colors?