Creating graphs the old-fashioned way with Ploticus

399

Author: Bruce Byfield

Ploticus is a throwback to the days when Unix programs did one thing, and did it well, using a minimum of system resources. Its SourceForge.net page hints at this orientation by describing Ploticus as “non-interactive” software for “just-in-time graph generation.” How useful it is depends on what you want to do, whether you use the settings that come with the program or define your own, and your willingness to master a lengthy — if well-documented — set of options.

Before using Ploticus, you should read its General FAQ to see it if will suit your needs. The FAQ explains that Ploticus produces only 2-D graphs and supports only basic statistical functions. Just as importantly, “it has scant support for mathematical formulas, scientific notations, or inline font or point size changes” and cannot be used with binary data. Unlike an application like OpenOffice.org, Ploticus makes no effort to be all things to all people — in fact, the FAQ specifically disavows marketing graphics packages and “chartjunk” effects, stressing that features such as clip-art and gradient backgrounds “have been intentionally avoided.” Knowing these limitations at the outset is important, because Ploticus takes time to learn, and you could waste your time if you start investigating the program with false expectations.

Using Ploticus

Ploticus’ man page and on-site documentation consists almost entirely of examples, with no basic instructions. However, with a little study, you can determine that your first step must be to write a data file. This data file is a plain text file with a .dat extension, in which data is displayed in columns delimited by a space, tab, or comma. The information in the data file includes labels, actual graph values, and formatting options.

For example, the data for a pie chart of how you spend your days might read:

Employment,8,red

In transit,2,orange

Meals,1,green

Errands,1,purple

Household chores,2,yellow

Recreation & relaxation,2,blue

Sleep,8,gray

Once you have created the data file, your next step is to decide whether to use a prefab — that is, one of the scripts that Ploticus supports by default — or write your own script for the graph. Ploticus’ documentation points out that you have more control with a script, but, against that benefit, you need to weigh the fact that you have to learn Ploticus’ scripting conventions first. The scripting language is not difficult, assuming you have even a rudimentary knowledge of programming, but the time you spend learning it could easily negate Ploticus’ time-saving ability to produce graphs on the fly unless you are a frequent user, or find an example that you can quickly customize.

The prefabs are more convenient, especially when you’re first exploring the program, since they cover the most common range of graphs, and the online Prefab Handbook details what options you need to include with each prefab. Besides, you can do enough customizing using the command’s extensive set of options that you might not even miss the power of a script. But be sure to take notes as you built your graph — it could take a nearly photographic memory to recall all the options you need to get the results you want.

For instance, if you are using the pie prefab, your command must include the data option to specify the data file, and the values option to specify which column of the data file specifies the information displayed on the graph. You can use more options for such purposes as adding a legend, identifying the field in the data file that holds labels, and adjusting the font size of labels.

Having chosen the options that you want for your prefab, your next step is to choose any additional options for generating the graph. When you run the ploticus command, it reads options sequentially left to right, and options specified later overwrite earlier ones, so check for possible conflicts before you produce your graph.

Normally, Ploticus writes the graph to a .png file in the same directory as the data file, but you can change the graphics format to .gif, .jpeg, .svg, or .swf — or simply display it on your screen — and redirect the output. You can easily set the graph size, its fonts and font sizes, and its background color with the appropriate options.

With somewhat more difficulty, you can also tweak the positioning of the graph’s legend or title, or crop it, either all around, or only on the sides specified. However, these options may require more trial and error than a person looking for quick output has time for.

Once you’ve chosen all your options, you are ready to generate your graph. As an example, the command for a relatively simple pie chart that uses the data file shown above is:

ploticus -prefab pie -png data=ploticustest.dat delim=tab values=2 labels=1 colorfld=3 title="Activity Hours" legend=yes name="Test Graph"

Note that the first option is the name of the prefab or the script. It is followed by the output format, then the name of the data file.

After all the setup, generation of the graph is almost an anticlimax, taking only a few seconds and returning no output to the command line except for detailed error messages that you can use to edit your commands. In the old Unix fashion, even a successfully created graph is not noted, requiring you to check the directory for the output file. The result, however, is a graph that you can show either directly from the desktop using a graphic view, or else easily import into a presentation or spreadsheet as required.

Conclusion

Ploticus is not for everyone. In particular, a dedicated desktop user with a phobia about the command line would balk at the sheer length of some of the commands necessary for fine control of the output. For such users, KChart is probably a better choice, since it also produces charts in independent files, but does so from a graphical interface.

At the same time, Ploticus is not nearly as formidable as it may seem during your first couple of experiments. The program really comes into its own if you are constantly generating the same kind of graph, and make the effort to put all the options that you are using into a script. If you are comfortable with the command line, you might even come to admire Ploticus’ old-fashioned ingenuity and attention to detail.

Categories:

  • Graphics & Multimedia
  • Desktop Software