slib-charplot

  1. slib-charplot
    1. Description
    2. Documentation
      1. Usage
      2. plot
      3. histograph
      4. plot-labels
      5. plot-dimensions
      6. plot-left-margin
      7. xborder-char
      8. yborder-char
      9. xaxis-char
      10. yaxis-char
      11. xtick-char
      12. bar-char
      13. curves-chars
    3. Example
    4. Author
    5. Maintainer
    6. Repository
    7. Requirements
    8. Version history
    9. License

Description

An opinionated port of the SLIB character plotting library.

For SLIB documentation see charplot.

Documentation

Note that the SLIB documentation describes charplot:dimensions, and other plot defining variables, that are not exported here. Rather parameters are provided.

Also, the plot and histograph procedures here accept optional arguments.

Usage
(import slib-charplot)
plot
[procedure] (plot COORDS [X-LABEL [Y-LABEL [FILL?]]])

Display a 2D plot of the COORDS, an array, list or vector of coordinate. With x,y axes label strings, X-LABEL & Y-LABEL. And the line vs filled graph type determined by FILL?.

COORDS
(or array list vector) ; coordinate data elements
X-LABEL
string ; x axis label, default see (plot-labels
Y-LABEL
string ; y axis label, default see (plot-labels
FILL?
boolean ; line is #f & filled is #t, default #f

The elements of a 1-dim list are Y, the missing X value is generated from [0 .. c-1], where c is the cardinality of the list. The elements of a 2-dim list are of the form (X Y1 ... Yn), where (<= 1 n N); N is 10, limited by the (string-length (curves-chars)).

Other accepted forms are: (X . Y) & (X (Y1 ... Yn)), which are interpreted as (X Y) & (X Y1 ... Yn), respectively.

The elements of a 1-dim array or vector are of type Y or (Y1 ... Yn). The missing X value is generated from [0 .. c-1], where c is the cardinality of the array or vector. The generated data is then (X Y ...).

The elements of a 2-dim array are interpreted as (X Y ...).

The following COORDS produce the same plot:

[procedure] (plot FUNC [X1 [X2 [NPTS]]])

Plots the function of the single-argument FUNC over the range X1 to X2. If the optional integer argument NPTS is supplied, it specifies the number of points to evaluate func at.

FUNC
(number -> float) ; function to plot
X1
number ; plot range start, default 0
X2
number ; plot range end, default 1
NPTS
exact-integer ; number of points to evaluate FUNC, default 64
histograph
[procedure] (histograph DATA [LABEL])

Creates and displays a histogram of the numerical values contained in vector or list DATA.

DATA
(or list vector) ; elements are number
LABEL
string ; plot label, default see (plot-labels
plot-labels
[parameter] (plot-labels [LABELER]) -> ((or array list vector) --> string string)

Procedure to supply default labels for each plot axis, x & y. Must be able to handle 1 & 2 dimensional data, supplying "" for missing y-axis data.

The default LABELER axis labels are "" "".

plot-dimensions
[parameter] (plot-dimensions [DIMS]) -> (or boolean (list exact-integer exact-integer))

A list of the maximum height (number of lines) and maximum width (number of columns) for the graph, its scales, and labels.

The default value uses the output-port-height and output-port-width of current-output-port at plot time.

DIMS
(or #f (list exact-integer exact-integer)) ; (Height-rows Width-columns), default #f

The left-margin effects the width consumed. The effective minimum dimensions are (4 (+ 5 (plot-left-margin))).

Use this instead of charplot:dimensions.

plot-left-margin
[parameter] (plot-left-margin [WID]) -> exact-integer
WID
(or #f exact-integer) ; Width-columns, default 2

2 is the the minimum value.

Use this instead of charplot:left-margin.

xborder-char
yborder-char
xaxis-char
yaxis-char
xtick-char
bar-char
[parameter] (xborder-char [CHAR]) -> char
[parameter] (yborder-char [CHAR]) -> char
[parameter] (xaxis-char [CHAR]) -> char
[parameter] (yaxis-char [CHAR]) -> char
[parameter] (xtick-char [CHAR]) -> char
[parameter] (bar-char [CHAR]) -> char

Use these instead of char:xborder, char:yborder, char:xaxis, char:yaxis, char:xtick & char:bar.

curves-chars
[parameter] (curves-chars [CHARS]) -> exact-integer
CHARS
(or #f string) ; characters to use for the plot curve, #f uses the default set.

Use this instead of char:curves.

Example

(import (chicken random) (srfi 42) slib-charplot)
(parameterize ((plot-dimensions '(20 40)))
  (plot (vector-ec (: i 64) (pseudo-random-real))) )
;=>
           _________________________
       8/5|-:                       |
          | :                       |
       7/5|-:                       |
          | :                       |
       6/5|-:                       |
          | :                       |
         1|-:            *   *      |
          | :   *   **    **        |
       4/5|-:             *         |
          | *    *          ***     |
       3/5|-:*****    **      *     |
          | :  *  * ** *   **  *    |
       2/5|-:      *    ** **       |
          | :*      *     *  *      |
       1/5|-* *   *   * *   * *     |
          | :** ** * *    *         |
         0|-:---------**-*----------|
          |_:_____._____:_____._____|
            0           40          80

Author

Aubrey Jaffer

Maintainer

Kon Lovett

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/slib-charplot

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Requirements

srfi-63

Version history

1.2.3
Allow 1-dim list plot. Fix plot signature.
1.2.2
.
1.2.1
.
1.2.0
Add plot-labels.
1.1.7
.
1.1.6
.
1.1.5
.
1.1.4
.
1.1.3
.
1.1.2
histograph label optional.
1.1.1
.
1.1.0
plot labels & range optional.
1.0.3
plot accepts a SRFI-63 array.
1.0.0
C5 release.

License

Copyright (C) 1992, 1993, 2001, 2003 Aubrey Jaffer

Permission to copy this software, to modify it, to redistribute it, to distribute modified versions, and to use it for any purpose is granted, subject to the following restrictions and understandings.

1. Any copy made of this software must include this copyright notice in full.

2. I have made no warranty or representation that the operation of this software will be error-free, and I am under no obligation to provide any services, by way of maintenance, update, or otherwise.

3. In conjunction with products arising from the use of this material, there shall be no use of my name in any advertising, promotional, or sales literature without prior written consent in each case.