A Collection of Gnuplot Examples - Alvinalexander
A Collection of Gnuplot Examples - Alvinalexander
com
alvin alexander
“Just Be”
a mindfulness reminder
app for Android
You’ll know that you need that command if you get this error message when you try to
run a plotcommand inside the gnuplotcommand line:
You can find more information about the need for this new brewcommand at this SO
link.
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 2/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
9 81
10 100
1, 1, 2, 5
2, 4, 4, 10
3, 9, 6, 15
4, 16, 8, 20
5, 25, 10, 25
6, 36, 12, 30
7, 49, 14, 35
8, 64, 16, 40
9, 81, 18, 45
10, 100, 20, 50
Note that the columns in the first file are separated by whitespace, and the columns in the
second file are separated by commas (a CSV file). The latest version of Gnuplot works
with both formats without requiring you to specify a column-separator.
Starting gnuplot
$ gnuplot
gnuplot>
It prompts you with gnuplot>as shown, but I won’t show that prompt in the examples
below.
Simple plotting
plot '2col.dat'
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 3/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
# simple plotting
plot '2col.dat' # assumes col1=x, col2=y; shows '+' at da
plot '2col.dat' with lines # connect points with a line
plot '2col.dat' with linespoints # line and points
plot '2col.dat' with points # just points (default)
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 4/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
plot '2col.dat' with lines title 'my curve' # this is really the line-title in the le
# abbreviations
plot '2col.csv' u 1:2 w l title 'Squared' # 'u' - using, 'w l' - with lines
This command
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 5/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
You can adorn your plots with titles, labels, legend, arrows, and more:
# labels
set label "boiling point" at 10, 212
# key/legend
set key top right
set key box
set key left bottom
set key bmargin
set key 0.01,100
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 6/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
# arrow
set arrow from 1,1 to 5,10
1, 1, 2, 5
2, 4, 4, 10
3, 9, 6, 15
4, 16, 8, 20
5, 25, 10, 25
6, 36, 12, 30
7, 49, 14, 35
8, 64, 16, 40
9, 81, 18, 45
10, 100, 20, 50
Multiple curves:
plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines
plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines, '4col.csv' using
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 7/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
Add a legend:
plot '4col.csv' using 1:2 with lines title 'Square', '4col.csv' using 1:3 with lines tit
Use abbreviations:
Multiple formulas:
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 8/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
ASCII plotting
You can create ASCII plots in your Mac Terminal window:
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 9/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
Plotting formulas
plot sin(x)
plot sin(x)/x
plot cos(x)
plot cos(x)/x
# grid
set grid
# ranges
set autoscale # let gnuplot determine ranges (default)
set xrange [1:10]
set yrange [1:100]
set xr [0.0:10.0]
set yr [0:5]
# tickmarks
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 10/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
set xzeroaxis lt -1
set x2zeroaxis lt -1
# logarithmic scale
set logscale
set logscale y
# see http://gnuplot.sourceforge.net/docs_4.2/node173.html
You can run shell commands from the Gnuplot command line:
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 11/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
Session management
When you work from the Gnuplot command line, you’re working in a session:
unset key
replot
Real‑world example
Here’s a quick real-world example. I had this dataset of my blood pressure and heart rate
from yesterday:
I then used this sequence of commands (including some trial and error that’s not shown):
set grid
set title 'BP and Heartrate'
set yrange [50:160]
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 12/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
It would be better to put the blood pressure on the y-axis on the left, and the heart rate on
the y-axis on the right, but I’m short on time, and haven’t learned how to do that yet.
Resources
I mostly learned about Gnuplot from the following resources:
http://gnuplot.sourceforge.net/demo/
http://www.cs.hmc.edu/~vrable/gnuplot/using-gnuplot.html
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 13/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
http://research.physics.illinois.edu/ElectronicStructure/498-
s97/comp_info/gnuplot.html
http://people.duke.edu/~hpgavin/gnuplot.html
http://gnuplot-tricks.blogspot.com/
http://lowrank.net/gnuplot/datafile-e.html
http://www.helsinki.fi/~jalaaman/gnuplot/index.html
Help
Help commands:
help
help terminal
Other notes:
Don’t type a blank space after the line continuation character, ”\"
Your data may be in multiple data files
category: technology
tags: plot graphics gnuplot chart
related
JavaPlot
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 14/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
what’s new
An RxScala example
Marble diagrams
Permalink
As a “note to self,” I just used these commands to create some charts for my Android
Football Game. I think the use of margins is one thing I haven’t shown before.
#
# Off Tackle Runs
#
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 15/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
reset
set lmargin 10
set rmargin 10
set tmargin 10
set bmargin 10
set title 'Off-Tackle Runs'
set xlabel 'Yards Gained'
set ylabel 'Percent Chance'
set xrange [-5:25]
set yrange [0:25]
set key top right
plot 'RunOffTackle_BaseD.dat' w lp title 'Base D', 'RunOffTackle_Nickel.dat' w lp titl
#
# Slant Passes
#
reset
set lmargin 10
set rmargin 10
set tmargin 10
set bmargin 10
set title 'Slant Passes'
set xlabel 'Yards Gained'
set ylabel 'Percent Chance'
set xrange [0:30]
set yrange [0:15]
set key top right
plot 'Slant_Base.dat' w lp title 'Base D', 'Slant_Nickel.dat' w lp title 'Nickel', 'Sl
Reply
The content of this field is kept private and will not be shown publicly.
Homepage
Subject
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 16/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
Comment
Save Preview
Links:
front page me on twitter search privacy
java
java applets
java faqs
misc content
java source code
test projects
lejos
Perl
perl faqs
programs
perl recipes
perl tutorials
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 17/18
27/08/2016 A collection of Gnuplot examples | alvinalexander.com
Unix
man (help) pages
unix by example
tutorials
source code
warehouse
java examples
drupal examples
misc
privacy policy
terms & conditions
subscribe
unsubscribe
wincvs tutorial
function point
analysis (fpa)
fpa tutorial
Other
mobile website
rss feed
my photos
life in alaska
how i sold my business
living in talkeetna, alaska
my bookmarks
inspirational quotes
source code snippets
http://alvinalexander.com/technology/gnuplot-charts-graphs-examples 18/18