Linux

  1. Home
  2. Computing & Technology
  3. Linux
Some Essential Linux Applications
Part 6 of the Linux Newbie Administrator Guide
 
 Related Resources
• Linux Newbie Administrator Guide
• 0. Linux Benefit
• 1. Before Installation
• 2. Linux Resources/Help
• 3. Basic Operations FAQ
• 4. Newbie Admin FAQ
• ~ 4.1 Lilo
• ~ 4.2 Drives
• ~ 4.3 X-Windows
• ~ 4.4 Configurations
• ~ 4.5 Networking
5. Shortcuts / Commands
• 6. Linux Applications
• 7. Learn Linux Commands
• A. How to Upgrade Kernel?
 

6.7 Automating creation of graphs with gnuplot

gnuplot is good for automating generation of graphs for numerical data and/or mathematical functions. For "interactive" generation of graphs, I prefer any spreadsheet. As old-fashioned as gnuplot may look, it can be quite handy if you want to periodically re-generate a graph or visualize (for inspection) massive amounts of data from a graph "template". gnuplot is flexible (many options available, including 3d plots) but one needs to take your time to learn it. Setting up a complex graph can take me 2 hours (but it's ok, if the graph is to be re-used many times over). The best help is to start gnuplot, and on the "gnuplot>" prompt, type "help".  gnuplot is available for Linux and MS Windows.

My data sets are stored in text (ASCII, *.dat) files. My "graph templates" are stored in gnuplot "command" files (*.gnu).  The output goes to a graphics file (*.png) which can be printed or imported to any word processor.
 
To generate a graph from an example gnuplot command file "make_graphs.gnu", I can do:
gnuplot make_graphs.gnu

To display the graph, I would do (in X terminal):

display my_graph.png

My example  "make_graphs.gnu" that generates an x-y graph follows.

# Comment are introduced with the hash (#)
# Stamp the graph with the current date and time
set timestamp "%Y-%m-%dT%T%z"
# This sets the graph resolution (the default is 100)
set samples 600
# Save the plot to a *.png file (make it colour)
set output "my_plot.png"
set terminal png color
#interesting terminals: png, x11, postscript, postscript eps, hpgl
set title "My Graph"   # Graph title
set xlabel "Distance [m]"      # title of x1 axis (bottom)
set x2label "Distance [feet]"  # title of x2 axis (top)
set ylabel "sin meters"        # title of y1 axis (left)
set y2label "log feet"         # title y2 axis (right)
set xtics  # control major tic marks on the axis
set x2tics; set ytics; set y2tics #commands can be separated with semicolons
set mytics # control minor tics on the axis, here I add them to the y axis
set xrange [0:15]          # Range for display on the x1 axis
set x2range [0:15.0/0.305] #Expressions are ok. This one converts meters to feet.
set yrange [*:*]           # The "*" sets the range to auto
set y2range [*:*]          # Range for the y2 axis
set nologscale  # or "set logscale x1x2y1y2" #Control logscale, linear scale is the default
set nogrid      # or "set grid" #Control gridlines, no grid is the default
set key outside # or "set nokey" #Control legend and its positions: "top", "bottom", "left"
# The following line creates the plot with 4 graph series
plot sin(x) axes x1y1, log(x) axes x2y2, "data.dat" using 1:2, \
   "data.dat" using 1:3
# Long lines can be split with \
# The third series uses columns 1 and 2 from the file
# The fourth plots the 3 column agains the 1st column from the data file.

Next > Part 7: Learning with Linux

Can't find what you are looking for?
Search the

Stay up-to-date!
Subscribe to the Linux free newsletter.

Explore Linux

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Linux

  1. Home
  2. Computing & Technology
  3. Linux

©2009 About.com, a part of The New York Times Company.

All rights reserved.