package printbox-ext-plot

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Extend PrintBox.t with plots of scatter graphs and line graphs

type plot_spec =
  1. | Scatterplot of {
    1. points : (float * float) array;
    2. content : PrintBox.t;
    }
    (*

    Places the content box at each of the points coordinates.

    *)
  2. | Scatterbag of {
    1. points : ((float * float) * PrintBox.t) array;
    }
    (*

    For each element of points, places the given box at the given coordinates.

    *)
  3. | Line_plot of {
    1. points : float array;
    2. content : PrintBox.t;
    }
    (*

    Places the content box at vertical coordinates points, evenly horizontally spread.

    *)
  4. | Boundary_map of {
    1. callback : (float * float) -> bool;
    2. content_true : PrintBox.t;
    3. content_false : PrintBox.t;
    }
    (*

    At evenly and densely spread coordinates across the graph, places either content_true or content_false, depending on the result of callback.

    *)
  5. | Map of {
    1. callback : (float * float) -> PrintBox.t;
    }
    (*

    At evenly and densely spread coordinates across the graph, places the box returned by callback.

    *)
  6. | Line_plot_adaptive of {
    1. callback : float -> float;
    2. cache : (float, float) Stdlib.Hashtbl.t;
    3. content : PrintBox.t;
    }
    (*

    At evenly and densely spread horizontal coordinates, places the content box at the vertical coordinate returned by callback for the horizontal coordinate of the placement position.

    *)

Specifies a layer of plotting to be rendered on a graph, where all layers share the same coordinate space. A coordinate pair has the horizontal position first.

type graph = {
  1. specs : plot_spec list;
    (*

    Earlier plots in the list take precedence: in case of overlap, their contents are on top. For HTML, we ensure that framed boxes and grids with bars are opaque.

    *)
  2. x_label : string;
    (*

    Horizontal axis label.

    *)
  3. y_label : string;
    (*

    Vertical axis label.

    *)
  4. size : int * int;
    (*

    Size of the graphing area in pixels. Scale for characters is configured by scale_size_for_text.

    *)
  5. axes : bool;
    (*

    If false, only the graphing area is output (skipping the axes box).

    *)
  6. prec : int;
    (*

    Precision for numerical labels on axes.

    *)
}

A graph of plot layers, with a fixed rendering size but a coordinate window that adapts to the specified points.

val default_config : graph

A suggested configuration for plotting, with intended use: Plot {default_config with specs = ...; ...}. The default values are: { specs = []; x_label = "x"; y_label = "y"; size = 800, 800; axes = true; prec = 3 }

type PrintBox.ext +=
  1. | Plot of graph
    (*

    PrintBox extension for plotting: scatterplots, linear graphs, decision boundaries... See graph and plot_spec for details.

    *)
val box : graph -> PrintBox.t

box graph is the same as PrintBox.extension ~key:"Plot" (Plot graph).

val concise_float : (prec:int -> float -> string) Stdlib.ref

The conversion function for labeling axes. Defaults to sprintf "%.*g".

val scale_size_for_text : (float * float) Stdlib.ref

To provide a unified experience across the text and html backends, we treat the size specification as measured in pixels, and scale it by !scale_size_for_text to get a size measured in characters. The default value is (0.125, 0.05).

OCaml

Innovation. Community. Security.