Page
Library
Module
Module type
Parameter
Class
Class type
Source
Oplot.SSourceMain Oplot functions
This module contains all functions for defining and rendering plots.
type view = Points.point * Points.pointtype view3 = Points.point3 * Points.point3type points = Points.point listtype curve3d = Points.point3 list * view3val black : colorval white : colorval red : colorval green : colorval blue : colorval yellow : colorval cyan : colorval magenta : color'Defining' means computing the coordinates of the points and lines to display, but not actually displaying them. We call a "sheet" a list of objects to be displayed.
type plot_object = | Points of pointsA list of points.
*)| Lines of points listThe points of each sublist are joined by a line segment.
*)| Poly of pointsClosed polygonal line.
*)| View of view optionIndicate the x-y range to display.
*)| Axis of axisAxis with divisions.
*)| Color of colorIndicate the color to draw subsequent objects.
*)| Text of textPosition a text at some (x,y) coordinate.
*)| Matrix of imatrixCheckboard-like matrix view with 0-255 greyscale.
*)| Grid of grid * gllist3D mountain-like representation of a matrix.
*)| Surf3d of surf3d * gllist3D parametric surface.
*)| Curve3d of curve3d * gllist3D points joined by line segments.
*)| Move3d of move3dAnimate the 3D object by a uniform rotation.
*)| Pause of intDisplay the current state of the sheet, and wait before displaying next object, but don't stop animation in the opengl window. This only works for interactive displays using the GL device.
| Freeze of intDisplay the current state of the sheet and suspend all display for the given time.
*)| Clear of colorClear graphics.
*)| Adapt of (view option * plot_object option) ref * view option -> plot_objectAny object that needs to adapt itself to the current View.
*)| User of view -> plot_device -> unitExecute any user-defined program.
*)| Anim of float -> plot_objectRepeatedly execute any user-defined program.
*)| Sheet of plot_object listGroup plot objects.
*)Helper functions for creating 2D plot objects
val point : (float * float) -> Points.pointA single point (x,y).
val axis : float -> float -> plot_objectaxis x0 y0 creates an Axis object with two axis crossing at the point (x0,y0).
Example:
# let a = axis 0. 0.;;
# display [ a ];;val parametric_plot :
(float -> float) ->
(float -> float) ->
?step:float ->
?adapt:bool ->
float ->
float ->
plot_objectparametric_plot fx fy t0 t1 computes a parametric curve given by the points (fx(t), fy(t)), for t varying from t0 to t1. If adapt is true, the step will adapt to the arc-length of the curve.
val point_plot_f :
(float -> float) ->
?step:float ->
float ->
float ->
plot_objectpoint_plot_f f x0 x1 computes a subset of the graph of the function f obtained by isolated points with a fixed horizontal step.
val line_plot_f :
(float -> float) ->
?step:float ->
float ->
float ->
plot_objectSimilar to point_plot_f but the points are joined by line segments.
val plot : (float -> float) -> ?step:float -> float -> float -> plot_objectAlias for line_plot_f.
val adapt_plot :
(float -> float) ->
?step:float ->
float ->
float ->
plot_objectSimilar to line_plot_f, but the plot will be dynamically cropped to the current view object. It returns an Adapt object.
val implicit_curve :
?pixel_size:(int * int) ->
?grid_size:(int * int) ->
?sub_size:(int * int) ->
?depth:int ->
?steps:int ->
?better:int ->
(float -> float -> float) ->
view ->
plot_objectimplicit_curve f (p0, p1) returns a Lines object that draws (an approximation) of the level set f x y = 0 inside the box delimited by the diagonal points p0,p1.
If the result is not satisfactory, or if you want a faster computation, you can play with the optional parameters; their meanings are explained in Isocurve.compute_level.
module Isocurve : sig ... endAdditional utilities for drawing and inspecting curves defined by an implicit equation.
val anim_plot :
(float -> float -> float) ->
?step:float ->
?t0:float ->
?t1:float ->
float ->
float ->
plot_objectIf f is a function two parameters t and x, then anim_plot f x0 x1 will generate an animation of the graph of the functions f t for t evolving with real time. The resulting object is of type Anim.
val dot_plot :
?dot:(float -> float -> plot_object) ->
?view:plot_object ->
(float * float) list ->
plot_object listdot_plot ~dot list draws a dot at each position (x,y) in the given list. Each dot is plotted using the dot function. By default, if ~dot is not specified, a single pixel is drawn. Another possibility is to use thediamond function.
val diamond : ?size:float -> float -> float -> plot_objectDraw a small diamond (lozange) at the given x y position.
val box : float -> float -> float -> float -> plot_objectbox x0 y0 x1 y1 draws a filled box given by the diagonal points x0,y0 and x1,y1.
val text : string -> ?size:int -> ?align:align -> float -> float -> plot_objecttext s x y draws the string s at the position (x,y).
val move_text : text -> Points.point -> unitMove text at position given by point.
val latex :
string ->
?size:int ->
?align:align ->
float ->
float ->
plot_objectSimilar to text but the rendered text is the result of LaTeX compilation of the given string.
val view : float -> float -> float -> float -> plot_objectview x0 y0 x1 y1 creates a View object indicating the bounding box for subsequent drawings.
Helper functions for creating 3D plot objects
val point3 : (float * float * float) -> Points.point3A single 3D point (x,y,z).
val surf3d_plot :
(float -> float -> float) ->
(float -> float -> float) ->
(float -> float -> float) ->
?width:int ->
?height:int ->
?wire:bool ->
float ->
float ->
float ->
float ->
plot_objectsurf3d_plot fx fy fz u0 v0 u1 v1 computes the parametric surface spanned by the map (u,v)->(fx(u,v), fy(u,v), fz(u,v)) when (u,v) varies in the range [u0,u1] ✕ [v0,v1].
val grid_plot :
(float -> float -> float) ->
?wire:bool ->
?width:int ->
?height:int ->
float ->
float ->
float ->
float ->
plot_objectgrid_plot f x0 y0 x1 y1 computes the graph of the function f of two variables x y, when (x,y) varies in the range [x0,x1] ✕ [y0,y1].
val color : float -> float -> float -> plot_objectSpecify the RGB color for subsequent drawings.
val line_width : float -> plot_objectSet line width for subsequent drawings.
val freeze : int -> plot_objectfreeze t creates a Freeze for t ms.
val pause : int -> plot_objectpause t creates a Pause for t ms.
val rotate : float -> float -> float -> float -> float -> plot_objectrotate x y z theta t rotates the 3D scene with angular velocity theta (in radians) aroung the axis (x,y,z), during time t.
val repeat : plot_objectval get_points2 : plot_object -> pointsObtain the list of 2D points, when relevant.
Various devices can be used to render the plots.
val display :
?dev:user_device ->
?fscreen:bool ->
?output:string ->
plot_object list ->
unitInitialize the graphics device and display the plot objects
val graphics : user_deviceSoftware rendering in a separate window.
val gl : user_deviceHardware (opengl) rendering in a separate window. This is the default. A few keys are active while the window is open. Press h for help.
val fig : user_deviceRender to an xfig file.
val xfig : user_deviceOpen in the xfig program, if present.
val eps : user_deviceRender to an EPS (encapsulated postscript) file.
val pdf : user_deviceRender to a PDF (portable document format) file.
val gv : user_deviceRender to EPS and open with a postscript viewer like gv.
val bmp : user_deviceRender to a BMP image. Deprecated. It will actually render a PNG image.
val png : user_deviceRender to a PNG image.
val img : user_deviceOpen in an image viewer.
The GL_SCALE is used to accomodate for HI-DPI screens. A "normal" screen of DPI about 110 should have GL_SCALE=1. A HI-DPI screen can typically have a scale of 2 or 2.5; on linux the GL_SCALE is detected at startup. It can be modified by the user.
val quit : ?dev:plot_device -> unit -> unitClose the current rendering window and clear the temporary directory.
These functions should not be used interactively, because they necessitate the graphics window to be already opened by display; but they can be interesting when programming a User object.
val set_color : ?dev:plot_device -> color -> unitval object_plot :
?addcounter:bool ->
dev:plot_device ->
plot_object ->
view option ->
unitDraw a single object, but not a Sheet. The device must have been initialized before.
If addcounter is true (default) the object will be considered as a new element of the currently displayed sheet; otherwise, it will be considered as being part of the currently displayed object: this only affects the Pause mechanism.
val user_flush : plot_device -> unitSynchronize graphics output by swapping back and front buffers. Hence two consecutive calls will result in flicker.
module Internal : sig ... endOplot internal functions are useful for creating user interfaces.