Sunteți pe pagina 1din 11

Gnuplot Tutorial

R F Evans

Introduction

Gnuplot is the worlds best 2D graphing package:

Highly customisable

Scriptable
Produces very professional graphs Small file sizes Fast and lightweight Available as a standard linux package

Scientific plotting recap

Graphs of scientific data need the following:

Title (or figure caption)


What

are you plotting against what?


What do the lines mean?

(Caption)

Axis labels
Units

Gnuplot in practice

Generate data for Gaussian function Plot with p "./data.dat" u 1:2 w lp

p stands for plot (data file) u stands for using (columns) w stands for with lp stands for linespoints

Gnuplot in practice

Lets set a more appropriate yrange and name our plot p [][0:1.1]"./data.dat" u 1:2 w lp ti Data

ti is short for title

Gnuplot in practice

Lets add a title and axis labels


set title Plot of Gaussian function set xlabel Value set ylabel Probability replot

Gnuplot in practice

A box histrogram would look nicer in black p [][0:1.1]"./data.dat" u 1:2 w boxes lt -1 ti "Data lt is line type

Gnuplot in practice

Hmm too many boxes


p [][0:1.1]"./data.dat" every 4 u 1:2 w boxes lt -1 ti "Data every specifies that every nth point is plotted

Gnuplot in practice

Finally output graph to file: set terminal postscript eps enhanced color "Palatino" 16

Here the font is set to Palatino there are others

set output plot.eps

Gnuplot Scripting
This can all be put in a script; plot.gpl # Set Terminal type

set terminal postscript eps enhanced color "Palatino" 16

# Set graph title


set title "Plot of Gaussian Function" # Set axis labels set xlabel "Value" set ylabel "Probability" # Set output file set output "plot.eps" # Plot data p [][0:1.1]"./data.dat" every 4 u 1:2 w boxes lt -1 # Convert file to pdf at the end sys "epstopdf plot.eps

ti "Data"

The script can then be run by typring: Gnuplot plot.gpl

Gnuplot in practice

Extra info:

http://t16web.lanl.gov/Kawano/gnuplot/index-e.html www.fisica.edu.uy/~marti/repartidos/gnuplotbook1.pdf

S-ar putea să vă placă și