Creating informative graphs with plotutils

Slashdot it! Delicious Share on Facebook Tweet! Digg!
Sebastian Duda, 123RF

Sebastian Duda, 123RF

Graphing

The plotutils package promises quick help to visualize numerical data in a variety of output formats.

An simple graph can help you visualize complex data and be a very useful tool in presentations and reports. The plotutils package [1] brings together a group of programs that all access the functions of GNU Libplot.

This library produces device-agnostic vector graphics and even animations in various output formats. There are bindings for C and C++ among other library classes. And, because of the effective interface programs for the shell, in most cases, you don't need to program anything – it's often enough to invoke a smartly crafted command line.

Installing Plotutils

The plotutils package is found in the major distribution repositories so that it can be set up easily with the corresponding package manager. In Ubuntu, you can just use the apt-get install plotutils command with administrative rights. This step pulls in all the necessary dependencies.

You select the desired output format (Table 1) with the -T option as an argument to the command, such as graph -T X … , where plotutils accepts multiple instances of -T . You just need to supply a suitable output redirection:

$ graph -T X -T PNG ... > output.png

Table 1

Plotutils Formats

Identifier Format
AI Adobe Illustrator
FIG Editable vector graphics format for the Fig program
GIF A simple version of GIF
Metafile GNU device-independent graphic format used internally
PNG PNG files, useful for further editing
PNM Portable Anymap, a universal bitmap format
PS PostScript, convertible to PDF
SVG Classic scalable vector graphics format
X X window display format that creates no output file

Several programs are used for graphics output. The main one is the graph program seen in the previous example. Using --help , you can display all the available options, which are surprisingly clear (see Table 2).

Table 2

Graph Options

Option Function
-T <format> Output format
-f <size> Font size in pixels
-F <font> Default font style
-g <style> Grid style (0 through 3 )
-h <height> Fractional height of the plot
-k <length> Length of tick marks
-K <clip_mode> Activates the clip mode
-r <shift> Shifts the plot horizontally by a fractional amount
-s Saves the screen
-u <shift> Shifts the plot vertically by a fractional amount
-w <width> Fractional width of the plot
--bitmap-size <X>x<Y> Size of the graph display
--max-line-length <length> Amount of points per line
--page-size <type> Output page type, such as "a4"
--pen-colors <colors> Pen colors as a string, such as "1=red, 2=green"
--rotation <degrees> Rotation angle
-E <axis> Toggles the X and Y axis ends
-l <axis> Toggles the axis between linear and logarithmic
-L <label> Text string for the top label
-N <axis> Toggles the presence of tick marks on axis
-x <limit> Sets limits for the X axis
-y <limit> Sets limits for the Y axis
-X <label> Text string label for the X axis
-Y <label> Text string label for the Y axis

The "plots" created with plotutils consist of the plotted curve, the X and Y axis with their labels, and other possible elements such as a plot title and background grid.

Graph accepts binary and plaintext files, with the latter being significantly easier to handle in that you can easily create and modify them in a text editor. You can use additional Graph options to interpret the input data (Table 3).

Table 3

More Graph Options

Option Function
-I <format> Defines format; a ASCII; e ASCII with error bars, g Gnuplot table format, f Single-precision binary, d Double-precision binary, i Integer binary
-a <increment> Automatically generates X axis values in the given increment
-B Toggles the line mode
-m <mode> Defines the line mode; 1 Solid, 2 Dotted, 3 Dot-dashed, 4 Short-dashed, 5 Long-dashed
-S <number> Draws a marker symbol at each data point; 1 Dot, 2 Plus sign, 3 Asterisk, 4 Degree, 5 Cross, 0 No symbol
-W <thickness> Defines the relative line thickness
-q <intensity> Defines the shading intensity (fill fraction) of the polygon formed from the line segments
-C Toggles between color and monochrome dataset rendering

In creating the command lines, pay particular attention to the order of options and arguments. The options control the presentation of the data values that follow. Apart from the command-line options, Graph provides a set of environmental variables, which the plotutils programs use as options. However, the command-line options override the environmental variables.

Line by Line

Graph reads the input data from a file or standard in. The program expects the data as simple space-separated X/Y value pairs, one for each measurement. Listing 1 shows an example. Note the use of options as comments at the beginning, which can also occur in the data and determine how the data that follows is represented.

Listing 1

Sample Input

#m=5,S=10
1422968301  140736
[...]
11422973527  137436

Alternatively the input can occur in one piece instead of line by line, such as when reading from standard in, as in the following example:

$ echo 1 1 2 2 3 1 1 1| graph -TX

Graph reads in the values as coordinate pairs. You can also use the -a option to specify reading in the values as Y axis values only – more on this later.

Another interpretation results when you use the -I e option to include error bars in output, which are common in normal measurements. In this case, Graph expects data triplets (x y <error> ), unless you enable -a again.

You should first test the data output in an X window (Figure 1). In this case, you can specify X as the output device (graph -T X <data> ) and the program will take care of things automatically. Pressing Q or clicking the window closes it again.

Figure 1: Graph easily and quickly displays output in an X window.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content