The (plotutils graph) library is mostly the graph
procedure, a single procedure with dozens of options
graph can take up to four arguments.
To plot sampled data, graph is called either with one list or two
lists of floating point data. When called with one list, the abscissa
will be created automatically. When called with two lists, they must be
equal length with one being the x-data and the other being the y-data.
To plot more than one set of sampled data on a plot, two lists can be
joined using the merge procedure.
(graph (merge xlist1 xlist2) (merge ylist1 ylist2))
To give each set of data its own style, call graph with a list of
datasets made by dataset (see below) instead.
To plot a single-valued function – a procedure that takes one numeric
argument and returns one numeric argument – graph can be called
with a procedure and two or three arguments that define the x-range of
the abcissa. When called with xstart and xend but not
xstep a default number of samples will be computed from the
procedure: a few hundred points. When xstep is included, it will
be the step size of the samples.
The graph is written to the port given by the #:outp keyword
argument, and error messages and warnings (such as a note that a point
was dropped from a logarithmic plot) to the port given by
#:errp; they default to the current output and error ports.
Invalid settings, such as a zero tick spacing or an infinite axis
limit, raise a Scheme error instead. As with newpl,
both must be backed by file descriptors, and anything already buffered
in them is written out before the graph, so output written to the port
before calling graph comes first.
Each point may have an error bar along either axis, or both, given by the ‘#:x-error’ and ‘#:y-error’ options (see Plot options).
There are a couple dozen optional parameters.
Configure a graph without drawing it. subgraph takes the
arguments graph takes (data and options), and returns the graph,
to be drawn by multigraph.
Draw graphs, a list of graphs made by subgraph, on one page,
like GNU graph’s --reposition option. Each graph is
drawn at the position and scale given by its ‘#:reposition’
option, in order; each after the first is drawn over a blanked-out
background (see ‘#:blankout’), so it can be an inset.
(multigraph
(list (subgraph xs ys #:top-label "Whole range")
(subgraph xs2 ys2 #:reposition '(0.55 0.55 0.35)
#:top-label "Detail"))
#:output-format "png" #:outp port)
The options of multigraph apply to the whole page:
‘#:output-format’, ‘#:bg-color’, ‘#:bitmap-size’,
‘#:emulate-color’, ‘#:max-line-length’, ‘#:page-size’,
‘#:rotation’, ‘#:portable-output’, ‘#:save-screen’,
‘#:outp’, and ‘#:errp’. Any not given are taken from the
first graph. All other options, such as axis limits and labels, belong
to each graph.
Make a dataset: one set of data, with its own style, for graph.
The data take the same forms as graph’s: a list of y values (the
x values are generated, as by ‘#:auto-abscissa’), lists of x and y
values, or a procedure with a range. Pass graph a list of
datasets to plot them together:
(graph (list (dataset xs ys)
(dataset xs zs #:line-mode 0 #:symbol 3)
(dataset sin 0 10 #:line-width 0.005 #:use-color #t))
#:top-label "Three datasets")
These keyword options set the dataset’s style. They take the values
the graph options of the same names take (see Plot options),
and each one that is not given takes the value of graph’s
option, or its default; so graph’s options set the style of every
dataset, and a dataset’s options change only that dataset.
#:line-modeThe linemode. Without it, the dataset takes the linemode that auto-bumping (see ‘#:toggle-auto-bump’ in Plot options) would give it if no dataset had set one, so setting it for one dataset doesn’t change the others.
#:symbolThe marker symbol, and optionally its size.
#:line-width#:fill-fraction#:symbol-font-nameAs for graph.
#:use-color#t to draw the dataset in color, #f in monochrome (the
graph option is ‘#:toggle-use-color’).
#:x-error#:y-errorError bars for the dataset’s points, as for graph.
Return #t if object is a dataset made by dataset.
Append one or more data lists into a single list, separating them with
#f, which graph treats as the end of one dataset and the
start of the next.
(merge '(1 2) '(3 4)) ⇒ (1 2 #f 3 4)
This merge replaces Guile’s core merge procedure, which
merges two sorted lists, in any module that imports
(plotutils graph). To keep using Guile’s merge as well,
import this one under another name, for example with
#:use-module ((plotutils graph) #:renamer (symbol-prefix-proc 'graph:))
or by excluding it with #:hide (merge).
Error bars are often known as absolute limits, such as the ends of a
confidence interval, rather than as distances from each point.
bounds->errors converts them: given a list of data values
and lists of the lows and highs of their error bars, it
returns a list of (lower . upper) pairs, the
distances from each value down to its low and up to its high, suitable
for ‘#:x-error’ or ‘#:y-error’. If a value, low, or high
is #f, that point gets no bar. The three lists must have the
same length, and each low must not exceed its value, nor the value its
high.
(bounds->errors '(10 20) '(8 15) '(11 26)) ⇒ ((2 . 1) (5 . 6)) (graph xs ys #:y-error (bounds->errors ys lows highs))