[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
@c=======================================================================
@c=======================================================================
1. Introduction | ||
2. Installation | ||
3. The Low Level Interface to PLplot | ||
4. The High Level Plotting Package | ||
5. Index |
@c=======================================================================
Cl-plplot provides a CFFI based interface to the PLplot graphics library. The PLplot graphics library supports the drawing of many different types of 2D and 3D graphs using a large variety of output devices including X11, postscript and png. PLplot can also be used to make scaled drawing, diagrams, etc...
At present, cl-plplot consists of two packages, one is low-level interface to the PLplot library and the other is high-level plotting interface that attempts to make using PLplot with Lisp easier. It has been tested on OS-X and debian linux with SBCL. Since it interfaces to the PLplot library using CFFI, it should work with any combination of lisp implementation and operating system that is supported by CFFI.
@c=======================================================================
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Cl-plplot depends on a working installation of the PLplot plotting library. This is available as a debian package, but it is also not too hard to compile from source on most systems. The current recommended debian package is libplplot-dev 5.6.1 in testing.
Once you have installed the PLplot library cl-plplot will hopefully not have any trouble finding the library. If you do encounter difficulties with cl-plplot finding the PLplot library, then the you will probably need to edit the function load-libraries in /cl-plplot/src/system. All that should be necessary is to provide the appropriate path to the library file 'libplplotd'.
@c=======================================================================
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The low level interface :cl-plplot-system
provides both 'direct' and 'wrapped' access to
the functions in the PLplot library. What this means is that each of
the functions in the PLplot library is available in two ways. The
'direct' form expects that all arguments are in a form appropriate
for handing off to the C library function. In cases where the C
function returns an array or a string it will be returned as C
pointer. On the other hand, the 'wrapped' form will automatically
convert Lisp variables to the appropriate C variables, fill in
any array size arguments and then call the 'direct' form.
In the case where the C function returns an
array or a string the 'wrapped' form will automatically convert
this into the appropriate Lisp type. Furthermore, the 'wrapped' form
takes care of allocating and deallocating the necessary memory to
make the C function call. The 'wrapped' form is recommended for
general use, but the 'direct' form is also available in situations
where speed may be important or you are already using C pointers
and do not want to pay the overhead of converting them back and
forth to Lisp variables.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(defcfun ("plarrows" c-plarrows) :void (u *plflt) (v *plflt) (x *plflt) (y *plflt) (n plint) (scale plflt) (dx plflt) (dy plflt)) (defun plarrows (u v x y scale dx dy) (let ((c-u (make-ptr u :double #'(lambda (x) (coerce x 'double-float)))) (c-v (make-ptr v :double #'(lambda (x) (coerce x 'double-float)))) (c-x (make-ptr x :double #'(lambda (x) (coerce x 'double-float)))) (n (length y)) (c-y (make-ptr y :double #'(lambda (x) (coerce x 'double-float))))) (unwind-protect (c-plarrows c-u c-v c-x c-y (funcall #'(lambda (x) (round x)) n) (funcall #'(lambda (x) (coerce x 'double-float)) scale) (funcall #'(lambda (x) (coerce x 'double-float)) dx) (funcall #'(lambda (x) (coerce x 'double-float)) dy)) (progn (foreign-free c-u) (foreign-free c-v) (foreign-free c-x) (foreign-free c-y))))) |
c-
appended onto the front. This convention is followed
for most PLplot functions.
make-ptr
handles the creation of a C array from
a Lisp vector.
n
required by PLplots arrows function is
automatically determined from the length of the vector y
and does not need to be passed in.
unwind-protect
so that if the C function fails the memory
occupied by c-u
, c-v
, c-x
and c-y
is still freed.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
src/system/api.lisp
where
all of the PLplot functions are defined.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The current best reference is the manual that comes with PLplot. TODO: a list of the supported PLplot functions and their arguments.
@c=======================================================================
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The high level interface :cl-plplot
tries to make PLplot
a little more Lispy using a CLOS based approach. You create
window objects, then associate axis objects, text objects and
plot objects to the window objects. When everything is set you
call the render
method on the window object to display
the plot using the display device of your choice.
This approach was adopted in part because the PLplot library does not support drawing multiple graphs simultaneously. By deferring the actual calls to the PLplot library until the moment when render is called on the window object, the user can build several graphs simultaneously. This also means that thread locks are a good idea in calls to render in a multi-threaded environment.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
window object |--axis object (1 for the x axis, 1 for the y-axis) | |--axis-label object (0 or more per axis object) | |--text-item object (1 per axis-label object) |--axis-label object (0 or more) |--plot object (0 or more) |--text-label object (0 or more) | |--text-item object (1 per text-label object) |--color-table object (1 per window) |--extended-color-table object (1 per window) |
Note that this is NOT an inheritance diagram. Each of the above objects is a distinct entity.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is the main object without which it is impossible
to actually create a plot. It always contains references to two
axis objects, one for the x-axis and one for the y-axis. It can
also contain references to additional axis-label objects that
might be used to provide a title for the plot as well as any
other axis labeling that is needed, references to plot objects
that will be drawn in the window and references to text labels
to draw in the window. When you call render
on a window
object it determines the coordinate system and size of the
plotting rectangle in which the plots will appear, then calls
the render
methods of the axis-label, text-label and
plot objects to create the final plot.
This is the main window object for drawing 3D plots. At present these include surface mesh plots (3D-mesh) and solid surface plots (surface-plot). This object inherits from the Window object, but due to limitations in the underlying PLplot library it is not as functional. Basically what this means is that drawing 2D plots in 3D is not recommended, you are not able to draw appropriately transformed text labels in 3D and you have less (no?) control over the locations of the axis labels.
This object is used to set minimum and maximum values to plot in the window, as well as specifying how to label the axis, major tick interval, minor tick interval, ticks, grid, ...
This object is used to draw text relative to one of the sides of the plotting rectangle. It specifies where to draw the text relative to one of the edges of the rectangle as well as in what orientation.
This is like the axis-label object except that it is typically drawn inside the plotting rectangle and its location is determined by the plot coordinate system.
This object is used to actually draw the text. It specifies font, size, color, superscript, ...
This object is used to convert data into a
plot. In its most generic form it contains two functions,
one that returns its preference for the x and y (and z if
relevant) ranges of the window coordinate system and another
that draws the object in the current window using
:cl-plplot-system
function calls. Specialized forms
currently include x-y-plot, bar-graph and contour-plot.
This object inherits from the plot object. Specialized forms currently include the 3D-mesh and surface-plot.
This object handles the use of PLplot's color map 0. Typically it
will consist of 16 colors, each of with contains red, green and blue
values as well as symbol (like :blue
) that you can use to refer
to the color. This color table is used by PLplot to draw essentially
all of the 'basic' items, i.e. lines, text, axises. You can have more
then 16 colors but not all of the graphics devices will handle that
many colors. Some in fact may only handle black and white.
This object handles the use of PLplot's color map 1. Typically this color table will contain anywhere between 128 to 256 different colors, though, again, not all graphics devices will handle so many colors. It used for shading plots, such as contour plots, where it is often desirable to have continuous range of colors rather than a few blocky colors.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Note: These are also available in src/examples/window-examples.lisp
.
(defun x-y-plot () (let* ((x (my-make-vector 40 #'(lambda(x) (* 0.1 x)))) (y (my-make-vector 40 #'(lambda(x) (* (* 0.1 x) (* 0.1 x))))) (p (new-x-y-plot x y)) (w (basic-window))) (add-plot-to-window w p) (render w "xwin"))) |
The vectors x and y are created using the function
y = x^2
. A x-y-plot object is then created to plot the vector x versus the
vector y. Finally a window object is created in which the x-y-plot
object p can be plotted. The x-y-plot object p is added to the window
w by the function add-plot-to-window
. Then the window is drawn
by calling the render
method and specifying what PLplot graphics
device to use for the graphical output ('xwin' is the X11 graphics device).
(defun bar-graph () (let* ((y (my-make-vector 10 #'(lambda(x) (* (* 0.2 x) (* 0.2 x))))) (b (new-bar-graph nil y :fill-colors (vector :grey))) (w (basic-window))) (add-plot-to-window w b) (render w "xwin"))) |
A vector y is created using the function y = (0.2 * x)^2
. This
vector is used to make a bar-graph object in which each of the bars
will be filled with the color grey. As in the X versus Y plot example,
a window w is created, the bar-graph object b is added to this window
and then the window is rendered using the X11 graphics device.
(defun contour-plot () (let ((c (new-contour-plot (my-make-matrix 50 50 #'(lambda (x y) (my-contour-plot-fn x y))) :x-min 0.0 :x-max 1.0 :y-min 0.0 :y-max 1.0 :fill-type :smooth)) (w (basic-window))) (add-plot-to-window w c) (render w "xwin"))) |
A contour plot object is created from a 2D matrix of
data. Additionally the coordinate system of the matrix is specified
with :x-min
, :x-max
, :y-min
and :y-max
and
the contour plot fill type is specified with :fill-type
. The
function my-make-matrix
is defined in src/examples/window-examples.lisp
.
(defun 3d-plot-1 () (let ((c (new-3d-mesh nil nil (my-make-matrix 50 50 #'(lambda (x y) (my-contour-plot-fn x y))) :line-color :blue)) (w (basic-3d-window :altitude 30 :azimuth 60))) (add-plot-to-window w c) (render w "xwin"))) |
A 3D-mesh object is created from a 2D matrix of
data. A 3D-window object is created in which to draw the 3D-plot
object, with the viewing angle specified by :altitude
and
:azimuth
. The plot is added to the window and is then
rendered using the X11 graphics device.
(defun surface-plot-1 () (let ((c (new-surface-plot nil nil (my-make-matrix 50 50 #'(lambda (x y) (my-contour-plot-fn x y))) :line-color :blue)) (w (basic-3d-window :altitude 30 :azimuth 60))) (add-plot-to-window w c) (render w "xwin"))) |
This example is essentially the same as the mesh plot example, except that we now create a surface-plot object.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(a-axis a-axis-label)
adds a-axis-label to a-axis.
(a-color-table new-color)
adds a new color #(r g b :smybol) to the end of a color table.
(a-window a-plot)
add-plot-to-window, adds a-plot to a-window.
(a-window a-text-label)
add-text-label-to-window, adds a-text-label to a-window.
none.
This (and greek-char, hershey-char, italic-font, normal-font,
number-symbol, overline, roman-font, script-font, subscript,
superscript, underline and unicode-char) exist to insert PLplot escape
sequences into a string. Cl-plplot uses the default PLplot escape
character “#”.
(&key (x-label x-axis) (y-label y-axis) (title cl-plplot) (background-color *background-color*) (foreground-color *foreground-color*))
creates a basic window object with ready-to-go axises.
(a-window a-plot)
organizes the plots so that a-plot is drawn on top.
none.
returns the default color table.
(a-3d-mesh &key line-width line-style line-color grid-type contour-options curtain)
Edits the visual properties of a 3D-mesh plot object.
(a-3d-window &key x-axis y-axis z-axis title foreground-color background-color window-line-width window-font-size viewport-x-min viewport-x-max viewport-y-min viewport-y-max plots text-labels color-table altitude azimuth)
edit-3D-window, edits the visual properties of a 3D-window.
(a-axis &key axis-min axis-max major-tick-interval minor-tick-number properties)
edit-axis, edits an axis.
(a-axis-label &key axis-text-item side displacement location orientation)
edit-axis-label, edits a axis-label object.
(a-bar-graph &key side-by-side line-colors fill-colors line-width filled)
edit-bar-graph, edits the visual properties of a bar-graph.
(a-contour-plot &key line-color line-width fill-type fill-colors)
edit-contour-plot, edits the visual properties of a contour plot.
(a-surface-plot &key line-width line-style line-color light-source surface-options)
edit-surface-plot, edits the visual properties of a solid surface plot.
(a-text-item &key the-text text-color text-justification font-size)
edit-text-item, edits a text-item object.
(a-text-label &key label-text-item text-x text-y text-dx text-dy)
edit-text-label, edits a text-label object.
(a-window &key x-axis y-axis title foreground-color background-color window-line-width window-font-size viewport-x-min viewport-x-max viewport-y-min viewport-y-max plots text-labels color-table)
edit-window, edits a window object.
(a-window which-axis &key axis-min axis-max major-tick-interval minor-tick-number properties)
allows the user to edit the axis of a window. which-axis should be one of the symbols :x or :y. see edit-axis for a more detailed explanation of the meaning of the different key words.
(a-x-y-plot &key line-width line-style symbol-size symbol-type color)
edit-x-y-plot, edits the visual properties of a x-y-plot.
(a-window device &key (size-x 600) (size-y 500))
get the location (in window coordinates) of the next mouse click. in order to do this the window must first be rendered so that the user has something to click on.
none.
none.
none.
(data-x data-y data-z &key contour-levels (copy t) (line-width 1) (line-style 1) (line-color *foreground-color*) (grid-type :grid-xy) contour-options curtain)
new-3D-mesh, creates a new 3D mesh (surface) plot object.
(&key x-axis y-axis z-axis title (window-line-width 1.0) (window-font-size *font-size*) (foreground-color *foreground-color*) (background-color *background-color*) (viewport-x-min 0.1) (viewport-x-max 0.9) (viewport-y-min 0.1) (viewport-y-max 0.9) plots text-labels color-table (altitude 60) (azimuth 30))
new-3D-window, creates and returns a new 3D-window object.
(&key axis-min axis-max (major-tick-interval 0) (minor-tick-number 0) (properties *axis-properties*) axis-labels)
new-axis, creates and returns an axis object.
(axis-text-item side displacement &key (location 0.5) (orientation parallel))
new-axis-label, create and returns a new axis label.
(x data &key bar-widths side-by-side line-colors fill-colors (line-width 1.0) (filled t) (copy t))
creates a new bar-graph plot object.
(&optional rgb-colors)
creates a new color table instance from a vector of rgb triples, which also includes a symbol to refer to the color by. for example: #((0 0 0 :black) (128 128 128 :grey) (255 255 255 :white)).
(data &key contour-levels (line-color *foreground-color*) (line-width 1) (fill-type none) fill-colors x-min x-max x-mapping y-min y-max y-mapping (copy t))
creates a new contour plot.
(min-max-function render-function)
allows the user to create their own custom plot object.
(&key control-points (color-table-size 128))
creates a new extended color table instance from a vector of control points. for example: #((0.0 0.0 0.0 0.0) (1.0 255 255 255)) will create a gray scale color table. see plscmap1l in the plplot documentation for a more thorough explanation.
(data-x data-y data-z &key contour-levels (copy t) (line-width 1) (line-style 1) (line-color *foreground-color*) light-source surface-options)
Creates a new 3D (solid surface) plot.
(the-text &key (text-color *foreground-color*) (text-justification 0.5) (font-size *font-size*))
new-text-item, creates and returns a new text item.
(label-text-item text-x text-y &key (text-dx 0.0) (text-dy 0.0))
new-text-label, creates and returns a new text-label object.
(&key x-axis y-axis title (window-line-width 1.0) (window-font-size *font-size*) (foreground-color *foreground-color*) (background-color *background-color*) (viewport-x-min 0.1) (viewport-x-max 0.9) (viewport-y-min 0.1) (viewport-y-max 0.9) plots text-labels color-table)
new-window, creates and returns a new window object.
(x y &key (copy t) (line-width 1) (line-style 1) (symbol-size 0.0) symbol-type (color *foreground-color*) x-error y-error)
creates a new x-y plot.
none.
none.
none.
(a-axis &optional a-axis-label)
remove-axis-label-from-axis, destructively removes a-axis-label from a-axis. if a-axis-label is not specified then the last axis-label is removed.
(a-color-table &optional color-to-remove)
removes color-to-remove, if specified, or the last color if not.
(a-window &optional a-plot)
remove-plot-from-window, destructively removes a-plot from a-window. if a-plot is not specified then the last plot is removed.
(a-window &optional a-text-label)
remove-text-label-from-window, destructively removes a-text-label from a-window. if a-text-label is not specified then the last text-label is removed.
(a-window device &key filename (size-x 600) (size-y 500))
renders a window and it associated plots and labels using device.
if you are using cl-plplot in a multi-threaded environment you should thread lock prior to calling render, as the plplot library only handles rendering one plot at a time.
none.
none.
(a-window a-plot)
organizes the plots so that a-plot is drawn on the bottom.
(a-window a-extended-color-table)
sets the color table associated with a-window to a-color-table. returns the old color table. (set-color-table (cl-plplot::window cl-plplot::color-table)) method documentation: sets the color table associated with a-window to a-color-table. returns the old color table.
(color)
switches the pen to the desired foreground color, or the default foreground color if the desired color cannot be found.
none.
none.
none.
none.
(a-color-table color-symbol new-color)
changes the color specified by color-symbol to new-color, which should be a rgb triple in the form #(r g b).
(data x-grid y-grid &key (algorithm grid-csa) optional-data)
calls the plplot function plgriddata to turn irregulary spaced data as (x,y,z) points into the 2d array data[i,j] = z. please see the plplot manual for further documenation.
@c=======================================================================
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | A B D E G H I N O R S U X |
---|
Jump to: | A B D E G H I N O R S U X |
---|
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Build Daemon user on January, 23 2008 using texi2html 1.78.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ Up ] | Up | Up section | 1.2 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated by Build Daemon user on January, 23 2008 using texi2html 1.78.