Module Gp

The workflow is:

  1. define your figure, ie a (module Plot) -> unit function
  2. decide on an output format (see Output terminals below)
  3. draw your figure: see draw below.

Simple example:

open Gp
let figure (module P: Plot) =
  P.plot (S "cos(x)") ~style:"l lc 8 lw 2" [ barebone ]
let () = draw ~output:(png "test.png") figure

Gnuplot parameters

type prms
val prms : ?tmp_root:string -> ?gnuplot:string -> ?init:string -> unit -> prms
  • parameter tmp_root

    Root directory for temporary files. Default: /dev/shm if it exists, otherwise /tmp.

  • parameter gnuplot

    Path to the gnuplot executable.

  • parameter init

    A string containing gnuplot commands to be executed right from the beginning. Default is "set key noautotitle; set border 3; set tics out nomirror".

Defining your figure

Plot properties

type side = [
| `left(*

left

*)
| `right(*

right

*)
| `top(*

top

*)
| `bottom(*

bottom

*)
]
type margin = [
| `left of float(*

left

*)
| `right of float(*

right

*)
| `top of float(*

top

*)
| `bottom of float(*

bottom

*)
]
type offset = [
| `left of [ `graph of float | `first of float ]
| `right of [ `graph of float | `first of float ]
| `top of [ `graph of float | `first of float ]
| `bottom of [ `graph of float | `first of float ]
]
type tics = [
| `auto(*

let gnuplot take care of it

*)
| `manual of (float * string) list(*

manual list

*)
| `regular of float * float * float(*

start, incr, end

*)
]
type property
val set : string -> property
val unset : string -> property
val load : string -> property
val barebone : property

Trim the plot to the bare minimum: no axes, no labels, no tics, nothing but your lovely plot. A great place to start for a beautiful plot.

val title : ?o:string -> string -> property
val margins : margin list -> property
val offsets : offset list -> property
val borders : ?o:string -> side list -> property
val tics : string -> property
val xtics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val ytics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val ztics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val cbtics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val x2tics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val y2tics : ?o:string -> [ `auto | `manual of (float * string) list | `regular of float list ] -> property
val xlabel : ?o:string -> string -> property
val ylabel : ?o:string -> string -> property
val zlabel : ?o:string -> string -> property
val cblabel : ?o:string -> string -> property
val x2label : ?o:string -> string -> property
val y2label : ?o:string -> string -> property
val xrange : ?o:string -> (float * float) -> property
val yrange : ?o:string -> (float * float) -> property
val zrange : ?o:string -> (float * float) -> property
val cbrange : ?o:string -> (float * float) -> property
val x2range : ?o:string -> (float * float) -> property
val y2range : ?o:string -> (float * float) -> property
val default_props : property list

Some decent default plot properties.

Types of data you can plot

type data =
| A of Owl.Mat.mat(*

An owl array; if it has a single row, it is interpreted as a single column

*)
| AP of Owl.Mat.mat(*

A "protected" owl array; if it has a single row, it is not interprted as a single column

*)
| L of Owl.Mat.mat list(*

A list of owl arrays, which are concatenated along the second axis before being passed to gnuplot. Again, arrays of size 1 x N are interpreted as N x 1 for convenience

*)
| F of (float -> float) * Owl.Mat.mat(*

A function f(x) over some x-range given as a 1xN or Nx1 matrix

*)
| S of string(*

A function as you would write in gnuplot

*)

Plotting functions

type item
val item : ?using:string -> ?axes:string -> ?legend:string -> ?style:string -> data -> item

See Plot.plot for meaning of parameters. Example:

let () =
  let x = Mat.gaussian 100 4 in
  let fig (module P: Plot) =
    P.plots 
      [ item (A x) ~using:"1:3" ~style:"p pt 7 lc 8 ps 0.5";
        item (A x) ~using:"2:4" ~style:"p pt 7 lc 7 ps 0.5" ]
      [ barebone ] in
  draw ~output:(png "test") fig
module type Plot = sig ... end

Contains all the commands you need to draw your figure

Output terminals

NB: if you are in a Jupyter notebook, you should not use any of the terminals below; instead, use Juplot.draw.

type output
val svg : ?font:string -> ?size:(int * int) -> ?other_term_opts:string -> string -> output
val png : ?font:string -> ?size:(int * int) -> ?other_term_opts:string -> string -> output
val qt : ?id:int -> ?font:string -> ?size:(int * int) -> ?other_term_opts:string -> ?pause:string -> unit -> output
val latex : ?term_opts:string -> string -> output
type tikz_font
val cmbright : tikz_font
val helvetica : tikz_font
val tikz : ?grid:bool -> ?crop:bool -> ?font:tikz_font -> ?tex:string -> string -> output

Drawing your figure

val draw : ?prms:prms -> output:output -> ((module Plot) -> unit) -> unit

Main drawing function: takes an output terminal (see Output terminals above) and a figure.

val interactive : ?interactive:bool -> ?size:(int * int) -> ((module Plot) -> unit) -> unit

This is a shorthand for draw ~output:(qt ());

  • parameter interactive

    (Default: false) Enables interactions with the QT windows, including zooming, etc. Your program will stall until you close the QT window though.

  • parameter size

    (Default: 600 x 400 pixels) Should be given in (y, x) pixel format.