Gnuplot

From Segfault
Jump to: navigation, search

Installation

Gnuplot should be available in most Linux distributions:

apt-get install gnuplot-nox                  # Debian, Ubuntu
yum install gnuplot-minimal                  # Fedora
emerge sci-visualization/gnuplot             # Gentoo

Usage

ab

Graph data from ab:

$ cat plot.p
set terminal png
set output "ab_2013-02-15.png"

# Nicer aspect ratio for image size
set size 1,0.7

set title "ApacheBench"
set grid y
set xlabel "requests"
set ylabel "response time (ms)"

# Plot data using column 9 with smooth sbezier lines
plot \
   "ab_n500-c10.dat"    using 9 smooth sbezier with lines title "ab_n500-c10",   \
   "ab_n500-c10-k.dat"  using 9 smooth sbezier with lines title "ab_n500-c10-k", \
   "ab_n500-c100.dat"   using 9 smooth sbezier with lines title "ab_n500-c100",  \
   "ab_n500-c100-k.dat" using 9 smooth sbezier with lines title "ab_n500-c100-k"
$ gnuplot plot.p

Note: gnuplot might issue warnings like:

$ gnuplot plot.p
Could not find/open font when opening font \
      "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf", \
      using internal non-scalable font

Indeed, when gnuplot is linked against libgd, it'll look for usable fonts in GDFONTPATH:

$ ldd `which gnuplot` | grep gd
       libgd.so.2 => /usr/lib/powerpc-linux-gnu/libgd.so.2 (0x0ff59000)

$ strings /usr/lib/powerpc-linux-gnu/libgd.so.2 | grep GD
GDFONTPATH

$ strings `which gnuplot` | grep _GDFONT
GNUPLOT_DEFAULT_GDFONT

The trick is to specify GDFONTPATH and GNUPLOT_DEFAULT_GDFONT:

$ ls -1R /usr/share/fonts/truetype/
/usr/share/fonts/truetype/:
ttf-dejavu                             # Only one font directory available due to
                                       # package ttf-dejavu-core
/usr/share/fonts/truetype/ttf-dejavu:
DejaVuSans-Bold.ttf
DejaVuSansMono-Bold.ttf
DejaVuSansMono.ttf
DejaVuSans.ttf
DejaVuSerif-Bold.ttf
DejaVuSerif.ttf

Export:

export GDFONTPATH=/usr/share/fonts/truetype/ttf-dejavu
export GNUPLOT_DEFAULT_GDFONT=DejaVuSansMono.ttf
gnuplot plot.p