Marco Fioretti explains how to use generic clip art to spice up your Gnuplot charts.
Gnuplot is a free software package that generates charts of all sorts. In previous posts, I've discussed how to use Gnuplot for time-based data and conditional plotting. This time, I'd like to introduce another class of potential core elements for your charts, and that's generic clip art. I'll explain step-by-step, in the simplest possible manner, how I plotted a histogram, and then I'll give you some directions on how to proceed from there.
First, clip art preparation
It may help, at least for your first experiment, to only use images of the same size (in pixels) for each chart. This isn't necessary, but it does make easier to understand exactly how the Gnuplot options described below work.
There are many ways to discover the size in pixels of an image. With the ImageMagick package, for example, this is how you would know that tux.original.png is 1320 pixels wide and 1570 high:
#> identify tux.original.png
tux.original.png PNG 1320x1570 ....
Instead, I used "convert" (another ImageMagick tool) to make a Tux version that's exactly (this is the meaning of the "\!" suffix) 200x200 pixels:
#> convert tux.original.png -resize 200x200\! tux.png
Next, some documentation
Gnuplot is very powerful, because it has a lot of options. Don't worry, though — here's the bare minimum you need to know to insert images inside your charts.
The plotting style that Gnuplot must use to paint generic raster graphics (images made by matrices of colored dots) inside a chart is called rgbimage. When working in this way, Gnuplot places the pixels of the original image, one by one, over the chart it's drawing.
Where does it place the pixels, you ask? Good question. By default, Gnuplot placse the lower left corner of an image in the origin of the X-Y plane. This would be (almost) all you need to set ONE image as the full background of a generic Gnuplot chart. In all other cases, you'll have to explicitly tell Gnuplot where to place each image. You can do this with the origin option:
This means just what you think it means: "Put the lower left corner of the current image in the point of coordinates X = 500 and Y = 0."
The last thing you should know before plotting with images is how to scale them. When Gnuplot draws in rgbimage mode, it doesn't necessarily "paint" each point of the chart with one and only one pixel of the image. That only happens when you give a unit value to both the dx and dy options. For example, if you set:
an image of 300x500 pixels will occupy an area of the chart that is 300 points wide and 500 high. Using "2" as dx value, instead, that same image will be stretched to fill a rectangle of the same height, but it will be twice as wide.
Finally, the code
Figure A was plotted with this simplified version of the official Gnuplot "barchart art" example.1 set terminal png linewidth 2.0 font ",40" size 2000,1000
Using clip art inside a Gnuplot chart.
Most of this code is basic Gnuplot stuff, already explained in countless examples, that defines basic properties of the chart: title, output file, label names, and so on. As far as we're concerned, the only important parts are line 10 and everything after the "plot" command.
Cbrange sets "the ranges of values [in an image] which are colored." Lines 13 to 15 (that to Gnuplot are only one line, thanks to the trailing backslashes) are what actually creates the image-based histogram. Using the options I just described, each line fills a different area, of a different size, with a different image. As a further example of how these commands work, Figure B is what you would get by setting "origin=(500,200)" for the FreeBSD mascotte.
Simplified version of the official Gnuplot "barchart art" example.
Beyond simple histograms
This post, which should be enough to show how images may make your Gnuplot charts more expressive, is just a beginning. First of all, who said that the numeric values in our example must be constant? You may certainly use that Gnuplot code as a template to fill each time with different origin and scaling values from a script. Even more important is the fact that nothing limits you to use graphics only as histogram bars. They may become illustrated captions or actual curve points, as in this more sophisticated example. You may even turn the whole concept upside down and use Gnuplot to better explain or describe images. To see what I mean, check out this picture of a longnose hawkfish with a Gnuplot scale.
What experience do you have with Gnuplot? Share your knowledge in the discussion thread below.