1.1 The Concept of Operations

Guile Plotutils has two components: one which basically does vector graphics onto image surfaces, and the other which graphs data.

For the plot component, the concept of operations is this

  1. Open a Guile port which will receive the output plot
  2. Create a <plparams> object, and use methods to set parameters that describe the output surface upon which graphics will be drawn.
  3. Create a <plotter> object, initialized with the <plparams> object, and then use its methods to draw upon the surface.
  4. Use appropriate methods to close the <plotter> object and the port, which writes the file.

A simple example could be this below, which opens a bitmap surface, creates a virtual pen, and then draws on the surface. Upon completion, a PNG file is created.

(use-modules (plotutils plot))
(define fp (open-output-file "tmp.png" #:binary #t))
(define param (newplparams))
(setplparam! param "BITMAPSIZE" "400x400")
(define plotter (newpl "png" fp (current-error-port) param))
(openpl! plotter)
(space! plotter 0.0 0.0 1000.0 1000.0)
(linewidth! plotter 0.25)
(pencolorname! plotter "red")
(erase! plotter)
(move! plotter 600.0 300.0)
(closepl! plotter)
(close fp)

The graph component expresses GNU Plotutils’s graphing capabilities, which can plot data or functions on a set of xy axes.

(use-modules (plotutils graph))
(define xvalues (iota 101 0 0.1))
(with-output-to-port ``tmp.png''
  (lambda ()
    (graph xvalues yvalues
           #:output-format ``png''
           #:top-label ``Title''))
  #:binary #t)