Module index

source download

Module: plot.lsp

Routines for creating data plots.

Version: 1.1 initial release
Version: 1.2 allow different length data vectors
Version: 2.0 added plotXY for plotting data points -> (x, y)
Version: 2.1 added plot:reset for resetting optional labels and settings
Version: 2.2 option plot:data-min, plot:data-max did not work
Author: Lutz Mueller, September 2011, April 2012

In its initial release the plot.lsp module can draw simple line plots from one to five data sets. In its simplest form only the plot command is necessary. A group of parameters can be set to further customize the plot. Plots can be save to a graphics file.

Load the module using:
(load "plot.lsp")
This module runs the newLISP Java based Guiserver. The file guiserver.jar is installed by one of the newLISP binary installers in a standard location. Executing (test-plot) will generate a test plots which can be seen here: line-plot and XY-plot .

Several variables can be set optionally to change the size, and positioning of the plot area in the image. Other variables can be set to control the partioning of the grid, labeling of the horizontal axis and legend. The following list shows all parameters with their default values:
 ; mandatory and preset with default values
 plot:wwidth        640 ; window width in pixels
 plot:wheight       420 ; window height in pixels
 plot:origin-x       64 ; top left x of plot area
 plot:origin-y       64 ; top left y of plot area
 plot:pwidth        520 ; width of plot area
 plot:pheight       280 ; height of plot area
; optional plot:data-min nil ; minimum value on the Y axis plot:data-max nil ; maximum value on the Y axis plot:title nil ; top centered main title plot:sub-title nil ; sub title under main title plot:unit-y nil ; a unit label centered left to the Y axis plot:labels nil ; a list of string labels for vertical grid plot:legend nil ; a list of string labels
; optional for plotXY only plot:data-x-min nil ; minimum value on the X axis plot:data-x-max nil ; maximum value on the X axis plot:data-y-min nil ; minimum value on the Y axis plot:data-y-max nil ; maximum value on the Y axis plot:unit-x nil ; a unit label centered under the X axis

Only the the first group of variables is mandatory and preset to the values shown above. Options in the second group will be either suppressed or set automatically.



syntax: (plot list-data [list-data . . . ])
parameter: list-data - One to five lists of data points.

The function draws one or more horizontal data lines from up to five data sets in list-data. Colors are chosen in the sequence red, green, blue, yellow and purple.

The following example doesn't set any extra options and plots to random data sets. Scale and labels on the vertical and horizontal axis will be set automatically. No title, sub-title and legends will be printed.

 (plot (random 10 5 50) (normal 10 0.5 50))
The following example sets several options then plots and exports the image to a PNG graphics file:

 (set 'plot:title "The Example Plot")
 (set 'plot:sub-title "several random data sets")
 (set 'plot:labels '("1" "" "20" "" "40" "" "60" "" "80" "" "100"))
 (set 'plot:legend  '("first" "second" "third" "fourth"))

 ; display plot image
 (plot (random 10 5 100) 
       (normal 10 0.5 100)
       (normal 8 2 100) 
       (normal 5 1 100) )

 ; save the displayed image to a file
 (plot:export "example-plot.png")



syntax: (plot:XY list-data-X list-data-Y)
parameter: list-data-X - List of X coordinates of data points.
parameter: list-data-X - List of Y coordinates of data points.

Draws data points of data in list-data-X and list-data-Y.



syntax: (plot:export str-file-name)
parameter: str-file-name - The name of the file.

Exports the current plot shown to a file in PNG format.

 (plot:export "example-plot.png")
See the example plot here .



syntax: (plot:reset)

Resets all optional labels and sizes to nil.

- ∂ -

generated with newLISP  and newLISPdoc