Gnuplot::Builder 0.20 released

I released a CPAN module called Gnuplot::Builder.

Gnuplot::Builder is a front-end module for Gnuplot. Gnuplot is a multi-platform plotting tool.

In this article I explain why I created yet another Gnuplot front-end for Perl.


I hate Gnuplot script. It's not that it's too complex or hard to remember. I've been using Gnuplot for ten years or so, and now I remember most of its syntax. I hate it because of the following problems.

  • Poor control flow. Until recently Gnuplot did not even have "if" or "while". User-defined subroutines are supported ONLY in file level (through "call" command).
  • Poor namespace and scoping. In Gnuplot everything is global. This makes it incredibly difficult to create modular and portable scripts. Even the dynamic scoping ("local" in Perl) is not supported.
  • Poor data structure. Gnuplot does not support complex user-defined data structures. Everything is stored in a flat namespace. There is no hierarchy.

In short, Gnuplot script is still too premature as a programming language.

I don't mean to blame Gnuplot developers for it, though. As a plotting tool, Gnuplot needs a lot of features other than a proper scripting environment. I don't even think it's a good idea to implement yet another scripting language on Gnuplot. I would rather try to embed Lua or MRuby or something like that than re-inventing the huge wheel.

Anyway, when I hate something, the next thing I do is try to solve it with Perl.

When I searched CPAN, I found bunch of Gnuplot front-end modules.

I tried Chart::Gnuplot but I thought it was not for me. It introduces its own abstraction layer over Gnuplot script, so you have to learn how to configure your plot in Chart::Gnuplot-style. I already know how to configure my plot by writing Gnuplot script. Why do I have to learn that again? It's ridiculous.

Too thick abstraction layers have another problem that they limit the capability of Gnuplot. Gnuplot is a very active project. Lots of new features are added to it in every release. If the abstraction layer is too thick, chances are that it won't allow you to use awesome new features of the latest Gnuplot.

So I created Gnuplot::Builder. As I wrote in the POD, it has the following features.

  • Gnuplot::Builder is object-oriented. Plot settings and dataset parameters are encapsulated in objects and they are totally isolated (in most cases). This resolves the "poor namespace and scoping" problem.
  • Gnuplot::Builder is thin. It just keeps Gnuplot sentences in a structured manner and streams them into a Gnuplot process. No one stops you from building eccentric Gnuplot scripts. This resolves the "too thick abstraction" problem.
  • Gnuplot::Builder is hierarchical. Gnuplot::Builder supports prototype-based inheritance similar to JavaScript's object system. This allows you to build a hierarchical configuration tree, where the most generic configuration is at the top and the most specific is at the bottom. This resolves the "poor data structure" problem.
  • Gnuplot::Builder works well in interactive shells. So you can use Perl shells to make interactive plots. You don't have to type Gnuplot scripts by hand in the Gnuplot interactive session anymore.

Gnuplot::Builder completely eliminates the necessity to write Gnuplot scripts by hand, so it resolves the "poor control flow" problem. Perl has great control flow mechanisms.