Wednesday, October 28, 2009

Gnuplot - Simple Tutorial

There are a ton of tutorials on how to use gnuplot, but most can be convoluted. Here is a simple example/tutorial for gnuplot.

1. Put data in a file (e.g. plot1.dat).  X-axis data followed by a space and Y-axis data

1 23.8
2 23.8
3 23.8
4 23.8
5 23.75
6 23.75
6.5 24.15
6.75 24.45
7 24.95
7.25 25.15
7.5 25.30
7.75 25.40
9 25.70
10 25.83
11 25.88
12 25.89
13 25.90
14 25.90

2. Put the setup commands in another file (e.g. plot1.setup)

# Basics
unset log
unset label
unset arrow
set xtic auto 
set ytic auto 
set autoscale

# Title Information
set title "Temperature vs. Time - Trial 1"
set xlabel "Time (min)"
set ylabel "Temperature (celsius)"

# Initial Point (1,23.80)
set label "i" at 2,24.8 font "Arial,25" offset 1
set arrow from 2,24.80 to 1,23.80

# Final Point (14,25.90)
set label "f" at 13,24.90 font "Arial,25" offset 1
set arrow from 13,24.90 to 14,25.90

# Time fired (6,23.75)
set label "a" at 6,24.75 font "Arial,25" offset 1
set arrow from 6,24.75 to 6,23.75

# Temp reaches 60% (7.1,25.04)
set label "b" at 8.1,25.04 font "Arial,25" offset 1
set arrow from 8.1,25.04 to 7.1,25.04

# Max Temp (13,25.90)
set label "c" at 12,24.90 font "Arial,25" offset 1
set arrow from 12,24.90 to 13,25.90

# Make the plot
plot "plot1.dat" with linespoints

3. Run the following command
   a. gnuplot -persist -raise plot1.setup

No comments:

Post a Comment