Changeset 40255 in project


Ignore:
Timestamp:
07/05/21 01:57:41 (3 weeks ago)
Author:
Kon Lovett
Message:

add example, add & explain limit on the # of "curves", document the line/filled plot option, point out optional argument difference vs source library

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/slib-charplot

    r39962 r40255  
    88=== Description
    99
    10 A port of the [[http://people.csail.mit.edu/jaffer/SLIB|SLIB]] character
    11 plotting library. For SLIB documentation see
    12 [[http://people.csail.mit.edu/jaffer/slib/Character-Plotting.html#Character-Plotting|charplot]].
     10An ''opinionated'' port of the
     11[[http://people.csail.mit.edu/jaffer/SLIB|SLIB]] character plotting library.
     12
     13For SLIB documentation see
     14[[http://people.csail.mit.edu/jaffer/slib/Character-Plotting.html#Character-
     15Plotting|charplot]].
    1316
    1417=== Documentation
    1518
    16 '''Note''' that the SLIB documentation describes {{charplot:dimensions}}.
    17 This, and other plot defining variables, are ''not'' exported here. Rather
     19'''Note''' that the SLIB documentation describes {{charplot:dimensions}}, and
     20other plot defining variables, that are ''not'' exported here. Rather
    1821{{parameter}}s are provided.
     22
     23Also, the {{plot}} and {{histograph}} procedures here accept optional arguments.
    1924
    2025===== Usage
     
    2429</enscript>
    2530
     31===== plot
     32
     33<procedure>(plot COORDS [X-LABEL [Y-LABEL [HISTOGRAM?]]])</procedure>
     34
     35Display a 2D plot of the {{COORDS}}, an {{array}}, {{list}} or {{vector}} of
     36''coordinate''. With x,y axes label strings, {{X-LABEL}} & {{Y-LABEL}}. And
     37the line vs filled graph type determined by {{HISTOGRAM?}}.
     38
     39; {{COORDS}} : {{(or array list vector)}} ; coordinate data elements
     40; {{X-LABEL}} : {{string}} ; x axis label, default {{""}}
     41; {{Y-LABEL}} : {{string}} ; y axis label, default {{""}}
     42; {{HISTOGRAM?}} : {{boolean}} ; line is {{#f}} & filled is {{#t}}, default {{#f}}
     43
     44The elements of a {{list}} are of the form {{(X Y1 ... Yn)}}, where {{(<= 1 n
     45N)}}; {{N}} is {{10}}, limited by the {{(string-length (curves-chars))}}.
     46
     47Other accepted forms are: {{(X . Y)}} & {{(X (Y1 ... Yn))}}, which are
     48interpreted as {{(X Y)}} & {{(X Y1 ... Yn)}}, respectively.
     49
     50The elements of a 1-dim {{array}} or {{vector}} are of type {{Y}} or {{(Y1 ...
     51Yn)}}. The missing {{X}} value is generated from {{[0 .. c-1]}}, where {{c}}
     52is the cardinality of the {{array}} or {{vector}}. The generated data is then
     53{{(X Y ...)}}.
     54
     55The elements of a 2-dim {{array}} are interpreted as {{(X Y ...)}}.
     56
     57The following {{COORDS}} produce the same plot:
     58* {{(list->array 2 '#() '((0 12 21) (1 21 12)))}}
     59* {{#((12 21) (21 12))}}
     60* {{((0 12 21) (1 21 12))}}
     61
     62<procedure>(plot FUNC [X1 [X2 [NPTS]]])</procedure>
     63
     64Plots the function of the single-argument {{FUNC}} over the range {{X1}} to
     65{{X2}}. If the optional integer argument {{NPTS}} is supplied, it specifies
     66the number of points to evaluate func at.
     67
     68; {{FUNC}}  : {{(number -> float)}} ; function to plot
     69; {{X1}} : {{number}} ; plot range start, default {{0}}
     70; {{X2}} : {{number}} ; plot range end, default {{1}}
     71; {{NPTS}} : {{exact-integer}} ; number of points to evaluate {{FUNC}}, default {{64}}
     72
     73===== histograph
     74
     75<procedure>(histograph DATA [LABEL])</procedure>
     76
     77Creates and displays a histogram of the numerical values contained in vector
     78or list {{DATA}}. {{LABEL}} is a string.
     79
     80; {{DATA}} : {{(or list vector)}} ; elements are {{number}}
     81; {{LABEL}} : {{string}} ; plot label, default {{""}}
     82
    2683===== plot-dimensions
    2784
    28 <procedure>(plot-dimensions [DIMS]) -> (or boolean (list exact-integer exact-integer))</procedure>
     85<parameter>(plot-dimensions [DIMS]) -> (or boolean (list exact-integer exact-integer))</parameter>
    2986
    3087A list of the maximum height (number of lines) and maximum width (number of
     
    3996are {{(4 (+ 5 (plot-left-margin)))}}.
    4097
    41 Use this {{parameter}} instead of {{charplot:dimensions}}.
     98Use this instead of {{charplot:dimensions}}.
    4299
    43100===== plot-left-margin
    44101
    45 <procedure>(plot-left-margin [WID]) -> exact-integer</procedure>
    46 
    47 ; {{WID}} : {{(or #f exact-integer)}} ; Width-columns, initial {{12}}, default {{2}}
     102<parameter>(plot-left-margin [WID]) -> exact-integer</parameter>
     103
     104; {{WID}} : {{(or #f exact-integer)}} ; Width-columns, default {{2}}
    48105
    49106{{2}} is the the minimum value.
    50107
    51 Use this {{parameter}} instead of {{charplot:left-margin}}.
     108Use this instead of {{charplot:left-margin}}.
    52109
    53110===== xborder-char
     
    58115===== bar-char
    59116
    60 <procedure>(xborder-char [CHAR]) -> char</procedure>
    61 <procedure>(yborder-char [CHAR]) -> char</procedure>
    62 <procedure>(xaxis-char [CHAR]) -> char</procedure>
    63 <procedure>(yaxis-char [CHAR]) -> char</procedure>
    64 <procedure>(xtick-char [CHAR]) -> char</procedure>
    65 <procedure>(bar-char [CHAR]) -> char</procedure>
    66 
    67 Use these {{parameter}}s instead of {{char:xborder}}, {{char:yborder}}, {{char:xaxis}},
     117<parameter>(xborder-char [CHAR]) -> char</parameter>
     118<parameter>(yborder-char [CHAR]) -> char</parameter>
     119<parameter>(xaxis-char [CHAR]) -> char</parameter>
     120<parameter>(yaxis-char [CHAR]) -> char</parameter>
     121<parameter>(xtick-char [CHAR]) -> char</parameter>
     122<parameter>(bar-char [CHAR]) -> char</parameter>
     123
     124Use these instead of {{char:xborder}}, {{char:yborder}}, {{char:xaxis}},
    68125{{char:yaxis}}, {{char:xtick}} & {{char:bar}}.
    69126
    70127===== curves-chars
    71128
    72 <procedure>(curves-chars [CHARS]) -> exact-integer</procedure>
     129<parameter>(curves-chars [CHARS]) -> exact-integer</parameter>
    73130
    74131; {{CHARS}} : {{(or #f string)}} ; characters to use for the plot curve, {{#f}} uses the default set.
    75132
    76 Use this {{parameter}} instead of {{char:curves}}.
    77 
    78 ===== plot
    79 
    80 <procedure>(plot COORDS [X-LABEL [Y-LABEL [HISTOGRAM?]]])</procedure>
    81 
    82 {{COORDS}} is an array, list or vector of coordinates, lists of x and y coordinates.
    83 {{X-LABEL}} and {{Y-LABEL}} are strings with which to label the x and y axes.
    84 
    85 ; {{COORDS}} : {{(or array list vector)}} ; coordinate data elements
    86 ; {{X-LABEL}} : {{string}} ; x axis label, default {{""}}
    87 ; {{Y-LABEL}} : {{string}} ; y axis label, default {{""}}
    88 ; {{HISTOGRAM?}} : {{boolean}} ; line or filled graph, default {{#f}}
    89 
    90 The elements of a {{list}} are of the form {{(X Y1 ... Yn)}}, where {{(< 0
    91 n)}}. Other accepted forms are: {{(X . Y)}} & {{(X (Y1 ... Yn))}}, which are
    92 interpreted as {{(X Y)}} & {{(X Y1 ... Yn)}}, respectively.
    93 
    94 The elements of a 1-dim {{array}} or {{vector}} are of type {{Y}} or {{(Y1 ...
    95 Yn))}}. The missing {{X}} value is generated from {{[0 .. c-1]}}, where {{c}}
    96 is the cardinality of the {{array}} or {{vector}}. The generated data is then
    97 {{(X Y ...)}}.
    98 
    99 The elements of a 2-dim {{array}} are interpreted as {{(X Y ...)}}.
    100 
    101 The following {{COORDS}} produce the same plot:
    102 * {{(list->array 2 '#() '((0 12 21) (1 21 12)))}}
    103 * {{#((12 21) (21 12))}}
    104 * {{((0 12 21) (1 21 12))}}
    105 
    106 <procedure>(plot FUNC [X1 [X2 [NPTS]]])</procedure>
    107 
    108 Plots the function of the single-argument {{FUNC}} over the range {{X1}} to
    109 {{X2}}. If the optional integer argument {{NPTS}} is supplied, it specifies
    110 the number of points to evaluate func at.
    111 
    112 ; {{FUNC}}  : {{(number -> float)}} ; function to plot
    113 ; {{X1}} : {{number}} ; plot range start, default {{0}}
    114 ; {{X2}} : {{number}} ; plot range end, default {{1}}
    115 ; {{NPTS}} : {{exact-integer}} ; number of points to evaluate {{FUNC}}, default {{64}}
    116 
    117 ===== histograph
    118 
    119 <procedure>(histograph DATA [LABEL])</procedure>
    120 
    121 Creates and displays a histogram of the numerical values contained in vector
    122 or list {{DATA}}. {{LABEL}} is a string.
    123 
    124 ; {{DATA}} : {{(or list vector)}} ; elements are {{number}}
    125 ; {{LABEL}} : {{string}} ; plot label, default {{""}}
     133Use this instead of {{char:curves}}.
     134
     135
     136=== Example
     137
     138* RNG Distribution
     139
     140<enscript highlight=scheme>
     141(import (chicken random) (srfi 42) slib-charplot)
     142((parameterize ((plot-dimensions '(20 40)))
     143  (plot (vector-ec (:+ i 64) (pseudo-random-real)))) )
     144;=>
     145           _________________________
     146       8/5|-:                       |
     147          | :                       |
     148       7/5|-:                       |
     149          | :                       |
     150       6/5|-:                       |
     151          | :                       |
     152         1|-:            *   *      |
     153          | :   *   **    **        |
     154       4/5|-:             *         |
     155          | *    *          ***     |
     156       3/5|-:*****    **      *     |
     157          | :  *  * ** *   **  *    |
     158       2/5|-:      *    ** **       |
     159          | :*      *     *  *      |
     160       1/5|-* *   *   * *   * *     |
     161          | :** ** * *    *         |
     162         0|-:---------**-*----------|
     163          |_:_____._____:_____._____|
     164            0           40          80
     165</enscript>
    126166
    127167
Note: See TracChangeset for help on using the changeset viewer.