7.4. Plotting Library
(lsh/libplot/plotter.lsh)


See: Plotting Functions.
This class library offers an alternate set of graph plotting functions besides those provided by the core interpreter (see Plotting Functions.) It contains the Plotter and the PlotterCurve classes providing functions for drawing multiple curves and modifying their appearance. Here is a sample code to plot various curves:
 (libload "libplot/plotter")
 ;; create a new plotter with default size (open a window if necessary)
 (setq p (new Plotter))  
 ;; plot log function in blue from 0 to 10.
 (==> p PlotFunc "log" log 0 10 0.1 (alloccolor 0 0 1))
 ;; show it on the screen
 (==> p redisplay)

 ;; add a piece of a red ellipse
 (==> p PlotXY "lips" sin cos 0 5 0.1 (alloccolor 1 0 0))
 (==> p redisplay)

 ;; plot a green polygonal sinusoid
 (setq x (range 0 10 0.5))
 (setq y (all ((v x)) (sin v)))
 (==> p plotlists "sine" x y (alloccolor 0 1 0) closed-circle)
 (==> p Redisplay)

 ;; add a grid
 (==> p SetGrid 1)
 (==> p Redisplay)

 ;; move the plotter to 100,0 and set its size to 300,200
 (==> p move 100 0)
 (==> p setsize 300 200)
 (cls)
 (==> p redisplay)

 ;; plot log function in a postscript file
 (let ((window (ps-window "/tmp/curve.ps")))
   (setq psp (new Plotter))
   (==> psp PlotFunc "log" log 0 10 0.1 (alloccolor 0 0 1))
   (==> psp redisplay))

 ;; plot log function in an editable graphic window using comdraw
 (setq window (comdraw-window))
 (setq cp (new Plotter)) 
 (==> cp PlotFunc "log" log 0 10 0.1 (alloccolor 0 0 1))
 (==> cp setgrid 1)
 (==> cp redisplay)


7.4.0. Plotter
(lsh/libplot/plotter.lsh)


Class Plotter This is the main class to define Plotter objects in Lush. Plotter objects have slots to define properties of the axes such as scales, labels, legend, title, ticks and logscale. It also stores the curves, lines and texts that will be drawn on the Plotter. rect slot of the Plotter specifies the rectangular area of the Plotter on the current current window. Slots of the Plotter object can be modified by methods of the class. They are computed automatically or set to their default values if not speicifed by the use.

7.4.0.0. (new Plotter [[x y] w h])
[CLASS] (lsh/libplot/plotter.lsh)


The constructor Plotter creates a new Plotter object at pixel positions (x, y), with width w and height h on the current window. If the window object is empty, it pops up a new window. x,y, w and h are optional. If x and y are omitted, they are both set to 0. If w and h are omitted, the size of the Plotter is equal to the size of the current window.
For example:
 (setq myplotter (new Plotter 600 600))



7.4.0.1. (==> Plotter move x y)
[MSG] (lsh/libplot/plotter.lsh)


move the upper left-hand corner of the plotter to screen position x y . No screen update is performed until the next call to redisplay.

7.4.0.2. (==> Plotter setsize w h)
[MSG] (lsh/libplot/plotter.lsh)


set the width and height of the plotter object to w and h . No screen update is performed until the next call to redisplay.

7.4.0.3. (==> Plotter Set attribute value)
[MSG] (lsh/libplot/plotter.lsh)


Sets the attribute of the Plotter object to the given value. The attribute argument is a string and can be "xticks", "yticks", "xscale", "yscale", "xlabel", "ylabel", "legend", "title", "grid", "xscale2", "yscale2", "xticks2", "yticks2", "xlabel2", "ylabel2". If an invalid attribute name is given error is generated. The value argument should match the attribute's data type. For "xticks", "yticks", "xticks2" and "yticks2" the value should be a list of numbers, for "xscale" and "yscale" it should be a list of two numbers, for "legend", "title", "xlabel", "ylabel", "xlabel2" and "ylabel2", it should be a string. Example:
 (==> myplotter Set "xticks" (range 0 10))
 (==> myplotter Set "xscale" (list 0 10))
 (==> myplotter Set "xlabel "x")
Individual methods are also provided to set and change the attributes of the Plotter object.

7.4.0.4. (==> Plotter SetRectNth i m n)
[MSG] (lsh/libplot/plotter.lsh)


Divides the current window into m by n rectangles and sets the rectangular area of the Plotter to the i th one. The first rectangle is the one on the upper left corner. When the rectangle of a Plotter object is set, the graphics plot is restricted to that rectangular area.

For example:

 ;;divides the current window vertically and 
 ;;plots the first object on the left and the second object on the right. 
 (==> plotter1 SetRectNth 1 1 2)
 (==> plotter2 SetRectNth 2 2 1)


7.4.0.5. (==> Plotter SetXScale xmin xmax)
[MSG] (lsh/libplot/plotter.lsh)


Sets the xscale slot of the Plotter . xmin argument is the minimum axis limit and xmax is the maximum axis limit on x. If a scale for x is not set, LUSH selects the axis limits based on the curve points.

7.4.0.6. (==> Plotter SetYScale ymin ymax)
[MSG] (lsh/libplot/plotter.lsh)


Sets the yscale slot of the Plotter . ymin argument is the minimum axis limit and ymax is the maximum axis limit on y. If a scale for y is not set, LUSH selects the axis limits based on the curve points.

7.4.0.7. (==> Plotter SetXTicks x)
[MSG] (lsh/libplot/plotter.lsh)


Sets the xticks slot of the Plotter . LUSH computes the ticks marks on the x axis based on the x scale. However the tick marks on the x axis can be specified with the SetXTicks method. Argument x is a list of numbers

7.4.0.8. (==> Plotter SetYTicks y)
[MSG] (lsh/libplot/plotter.lsh)


Sets the yticks slot of the Plotter . LUSH computes the ticks marks on the y axis based on the y scale. However the tick marks on the y axis can be specified with the SetYTicks method. Argument y is a list of numbers.

7.4.0.9. (==> Plotter SetXLabel x)
[MSG] (lsh/libplot/plotter.lsh)


Adds axis label to the x axis. Argument x is a string.

7.4.0.10. (==> Plotter SetYLabel y)
[MSG] (lsh/libplot/plotter.lsh)


Adds axis label to the y axis. Argument y is a string.

7.4.0.11. (==> Plotter SetLegend l)
[MSG] (lsh/libplot/plotter.lsh)


Adds a legend text to the up right corner of the Plotter rectangle. Argument l is a string.

7.4.0.12. (==> Plotter SetTitle t)
[MSG] (lsh/libplot/plotter.lsh)


Adds a title text to the top of the Plotter rectangle. Argument t is a string.

7.4.0.13. (==> Plotter SetGrid x)
[MSG] (lsh/libplot/plotter.lsh)


Specifies whether to draw grid lines or not. Argument x is either 0 or 1. When x is 1 grid lines are drawn, when x is 0 grids are not drawn.

7.4.0.14. (==> Plotter SetXScale2 xmin xmax)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double x axes. SetXScale2 method sets the scale of the second x axis. xmin argument is the minimum axis limit and xmax is the maximum axis limit on the second x axis. If no scale is specified for the second x axis, it is not drawn.

7.4.0.15. (==> Plotter SetYScale2 ymin ymax)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double y axes. SetYScale2 method sets the scale of the second y axis. ymin argument is the minimum axis limit and ymax is the maximum axis limit on the second y axis. If no scale is specified for the second y axis, it is not drawn.

7.4.0.16. (==> Plotter SetXTicks2 x)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double x axes. SetXTicks2 method sets the tick marks of the second x axis. Argument x is a list of numbers indicating the tick marks.

7.4.0.17. (==> Plotter SetYTicks2 x)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double y axes. SetYTicks2 method sets the tick marks of the second y axis. Argument y is a list of numbers indicating the tick marks.

7.4.0.18. (==> Plotter SetXLabel2 x)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double x axes. SetXLabel2 method sets the label of the second x axis. Argument x is a string.

7.4.0.19. (==> Plotter SetYLabel2 y)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw graphs with double y axes. SetYLabel2 method sets the label of the second y axis. Argument y is a string

7.4.0.20. (==> Plotter SetXLogScale)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw logplots. SetXLogScale method converts the scale of the x axis to log.

7.4.0.21. (==> Plotter SetYLogScale)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw logplots. SetYLogScale method converts the scale of the y axis to log.

7.4.0.22. (==> Plotter ResetXLogScale)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw logplots. ResetYLogScale method converts the scale of the x axis from log to regular.

7.4.0.23. (==> Plotter ResetXLogScale)
[MSG] (lsh/libplot/plotter.lsh)


Using the Plotter library it is possible to draw logplots. ResetYLogScale method converts the scale of the x axis from log to regular.

7.4.0.24. (==> Plotter NewCurve name)
[MSG] (lsh/libplot/plotter.lsh)


Adds a new PlotterCurve object to the Plotter . name is the name of the curve and of type string. Curves are stored as alists in the Plotter objects. Each PlotterCurve is associated with a name and with the NewCurve method added to the list of curves in the Plotter .

7.4.0.25. (==> Plotter ClearCurve curvename)
[MSG] (lsh/libplot/plotter.lsh)


Deletes the PlotterCurve object named curvename form the Plotter .

7.4.0.26. (==> Plotter AddPoint curvename x y)
[MSG] (lsh/libplot/plotter.lsh)


Adds the data point ( x, y ) to the PlotterCurve object named curvename to the Plotter . If a curve named curvename does not exist, error is returned.
For example:
 (==> myplotter AddPoint "S" 0 10) 


7.4.0.27. (==> Plotter SetCurveColor curvename c)
[MSG] (lsh/libplot/plotter.lsh)


Sets the color of the PlotterCurve object named curvename to color c . Argument c is a color number (as returned by alloc-color ). If a curve named curvename does not exist, error is returned.

7.4.0.28. (==> Plotter SetCurveSymbol curvename symbolfunc)
[MSG] (lsh/libplot/plotter.lsh)


Sets the marker symbol of the PlotterCurve object named curvename to symbol symbolname . Argument symbolfunc must be a two-argument function whose role is to draw a symbol at the screen coordinates passed as arguments. A set of pre-defined such functions are provided: open-square , closed-square , open-circle , closed-circle , open-up-triangle , open-down-triangle , closed-up-triangle , closed-down-triangle , straight-cross and oblique-cross .

7.4.0.29. (==> Plotter SetCurveSymbolSize curvename symbolsize)
[MSG] (lsh/libplot/plotter.lsh)


Sets the size of the marker of the PlotterCurve named curvename to symbolsize . symbolsize is an integer normally between 1 and 5. If symbolsize is set to 0 no markers are drawn at data points.
For example:
 
  (==> myplotter SetCurveSymbolSize "s" 3) 


7.4.0.30. (==> Plotter SetCurveLine curvename line)
[MSG] (lsh/libplot/plotter.lsh)


Specifies whether to draw lines between markers of the PlotterCurve object or not. Argument line is 0 or 1. If line is 0 only markers at data points are drawn, if line is 1, markers are connected. By default, line is 1.

7.4.0.31. (==> Plotter SetCurveXAxis curvename xaxis)
[MSG] (lsh/libplot/plotter.lsh)


In case of use of double x axes, associates the PlotterCurve object to the x axis specified by the argument xaxis . If xaxis argument is 0 the x axis at the bottom is used (default), if it is 1, x axis at the top is used to draw the curve. The scales for the second (top) axis should be set.

7.4.0.32. (==> Plotter SetCurveYAxis curvename yaxis)
[MSG] (lsh/libplot/plotter.lsh)


In case of use of double y axes, associates the PlotterCurve object to the y axis specified by the argument yaxis . If yaxis argument is 0 the y axis on the left is used (default), if it is 1, x axis on the right is used to draw the curve. The scales for the second (right) axis should be set.

7.4.0.33. (==> Plotter PlotFunc curvename func xmin xmax xstep [color] [symbol])
[MSG] (lsh/libplot/plotter.lsh)


Plot a scalar real function. Samples are computed for are all values between xmin and xmax by step of xstep . color is a color identifier (as returned by alloccolor ), and symbol is a function of two arguments (x and y coordinates) that is called each time a data point is to be plotted. Predefined such functions include nil (no symbol is plotted), open-square, closed-square, open-circle, closed-circle, open-up-triangle, open-down-triangle, closed-up-triangle, closed-down-triangle, straight-cross and oblique-cross, or any user-defined functions
Example:
 (libload "libplot/plotter")
 (setq p (new Plotter))
 (==> p PlotFunc "log" log 0 10 0.1 (alloccolor 1 0 0))
 (==> p redisplay)


7.4.0.34. (==> Plotter PlotXY curvename funcx funcy tmin tmax tstep [color] [symbol])
[MSG] (lsh/libplot/plotter.lsh)


Plot a parameterized curve (X(t), Y(t)). Samples are computed for are all values of t between tmin and tmax by step of tstep . color is a color identifier (as returned by alloccolor ), and symbol is a function of two arguments (x and y coordinates) that is called each time a data point is to be plotted. Predefined such functions include nil (no symbol is plotted), open-square, closed-square, open-circle, closed-circle, open-up-triangle, open-down-triangle, closed-up-triangle, closed-down-triangle, straight-cross and oblique-cross, or any user-defined functions
Example:
 (libload "libplot/plotter")
 (setq p (new Plotter))
 (==> p PlotXY "log" log 0 10 0.1 (alloccolor 1 0 0))
 (==> p redisplay)


7.4.0.35. (==> Plotter PlotLists curvename xlist ylist [color] [symbol])
[MSG] (lsh/libplot/plotter.lsh)


Plot a list of points whose x and y coordinates are corresponding elements in xlist and ylist . In other words xlist is the list of x coordinates of the data ylist is the list of y coordinates of the datapoints. curvename is a curve identifier (generally a string). If the curve curvename already exists, it is replaces. color is a color identifier (as returned by alloc-color ), and symbol is a function of two arguments (x and y coordinates) that is called each time a data point is to be plotted. Predefined such functions include open-square, closed-square, open-circle, closed-circle, open-up-triangle, open-down-triangle, closed-up-triangle, closed-down-triangle, straight-cross and oblique-cross.
Example:
 (==> myplotter PlotLists "log" (range 1 100) (mapcar log x))


7.4.0.36. (==> Plotter AddText x y txtstring)
[MSG] (lsh/libplot/plotter.lsh)


Adds a new text to the Plotter object. Texts are stored as list of lists in the Plotter . Each element of the text list is a list of the coordinates of the corresponding text and its string. Arguments x and y are real coordinates (coordinates on the plotter)

7.4.0.37. (==> Plotter AddLine x1 y1 x2 y2)
[MSG] (lsh/libplot/plotter.lsh)


Adds a new line to the Plotter object. Lines are stored as list of lists in the Plotter . Each element of the line list is a list of the coordinates of the line. Arguments x1, x2, y1 and y2 are real coordinates (coordinates on the Plotter).

7.4.0.38. (==> Plotter GetClick)
[MSG] (lsh/libplot/plotter.lsh)


Returns the real coordinates of the point clicked on the Plotter . This method is not supported in a Comdraw window

7.4.0.39. (==> Plotter GetDistance)
[MSG] (lsh/libplot/plotter.lsh)


Computes the the length of the vector drawn by dragging and dropping the mouse pointer on the Plotter . The distance is in real coordinates (coordinates of the plotter). This method is not supported in a Comdraw window.

7.4.0.40. (==> Plotter Redisplay [location])
[MSG] (lsh/libplot/plotter.lsh)


This is fundamental method of a Plotter object. Every curve, line, text, etc is stored in the Plotter object and is drawn after a Redisplay command. To see the modifications on the window, Redisplay should be called. The argument location is optional. It is a list of x and y pixel coordinates, width and height of the Plotter . If specified as (list x y w h), it displays the Plotter in the rectangular area (x y w h).

For example:

 ;;locates and reprints the plotter in the rectangle 
 ;;specified by (100,100,500,500) on current window
 (==> myplotter Redisplay 100 100 500 500)



7.4.1. Low-Level Utility Functions
(lsh/libplot/plotter.lsh)




7.4.1.0. (compute-xscale pobject)
(lsh/libplot/plotter.lsh)


Computes the scale of the x axis for a given Plotter object from the data points in each curve.

7.4.1.1. (compute-yscale pobject)
(lsh/libplot/plotter.lsh)


Computes the scale of the y axis for a given Plotter object from the data points in each curve.

7.4.1.2. (set-axes axes xscale yscale xticks yticks xlabel ylabel legend title grid [xlogscale] ylogscale])
(lsh/libplot/plotter.lsh)


Plots the axes given the scales of the x and y axis, axis ticks, axis labels, legend and the title. Labels, legend and title can be empty strings. The axes argument is a list of xaxismin, yaxismin, xaxismax and yaxismax. xaxismin and yaxismin are the pixel coordinates of the origin of the xaxes, and xaxismax and yaxismax are the pixel coordinates of the top right corner of the axes. The grid argument is either 1 or 0, specifies whether to have grid on the plotter or not. xlogscale and ylogscale are optional and are used if a logscale is desired on one of the axes.

For example:

 (set-axes (list 100 600 800 100) 
   (list 0 10) (list 0 10) (range 0 10) (range 0 10) "x" "y" "" "graph" 1)