Sign in

    Lampese/mathplotlib/scene/gridspec does not have a README file

    LayoutError

    pub(all) suberror LayoutError {
    InvalidDimension
    InvalidSpacing
    InvalidRatios
    InvalidBounds
    CellOutOfBounds
    }

    Errors raised by grid layout construction and indexing.

    GridSpec

    pub struct GridSpec {
    rows : Int
    columns : Int
    hspace : Double
    vspace : Double
    width_ratios : Array[Double]
    height_ratios : Array[Double]
    share_x : ShareMode
    share_y : ShareMode
    // private fields
    }

    A regular rows-by-columns grid with deterministic spacing.

    GridSpec::cell

    fn GridSpec::cell(self : GridSpec, row : Int, column : Int, figure_width : Int, figure_height : Int, margin : Int) -> Rect raise LayoutError

    Compute one cell rectangle inside a figure display area.

    GridSpec::cell_spec

    fn GridSpec::cell_spec(self : GridSpec, row : Int, column : Int) -> SubplotSpec raise LayoutError

    Select one cell as a SubplotSpec.

    This is the explicit equivalent of Matplotlib's gs[row, column] indexing, while remaining convenient to call from MoonBit.

    GridSpec::cells

    fn GridSpec::cells(self : GridSpec, figure_width : Int, figure_height : Int, margin : Int) -> Array[Rect] raise LayoutError

    Compute all cell rectangles in row-major order.

    GridSpec::columns

    fn GridSpec::columns(self : GridSpec) -> Int

    GridSpec::geometry

    fn GridSpec::geometry(self : GridSpec) -> (Int, Int)

    Return the row and column dimensions of this grid.

    GridSpec::get_geometry

    fn GridSpec::get_geometry(self : GridSpec) -> (Int, Int)

    Matplotlib-compatible name for geometry.

    GridSpec::get_height_ratios

    fn GridSpec::get_height_ratios(self : GridSpec) -> Array[Double]

    Matplotlib-compatible name for the height ratios getter.

    GridSpec::get_width_ratios

    fn GridSpec::get_width_ratios(self : GridSpec) -> Array[Double]

    Matplotlib-compatible name for the width ratios getter.

    GridSpec::height_ratios

    fn GridSpec::height_ratios(self : GridSpec) -> Array[Double]

    Return relative heights for the grid rows.

    GridSpec::hspace

    fn GridSpec::hspace(self : GridSpec) -> Double

    GridSpec::index

    fn GridSpec::index(self : GridSpec, index : Int) -> SubplotSpec raise LayoutError

    Select a cell by its row-major flat index.

    Negative indices count from the end, matching Python's indexing rule.

    GridSpec::rows

    fn GridSpec::rows(self : GridSpec) -> Int

    GridSpec::set_height_ratios

    fn GridSpec::set_height_ratios(self : GridSpec, values : Array[Double]) -> Unit raise LayoutError

    Set relative heights for the grid rows.

    GridSpec::set_hspace

    fn GridSpec::set_hspace(self : GridSpec, value : Double) -> Unit raise LayoutError

    Update the horizontal gap between grid columns.

    The value is measured as a fraction of the average cell width. Because nested grids retain the parent layout reference, existing child subplot rectangles observe this change immediately.

    GridSpec::set_vspace

    fn GridSpec::set_vspace(self : GridSpec, value : Double) -> Unit raise LayoutError

    Update the vertical gap between grid rows.

    The value is measured as a fraction of the average cell height and is visible through all nested subplot specifications belonging to this grid.

    GridSpec::set_width_ratios

    fn GridSpec::set_width_ratios(self : GridSpec, values : Array[Double]) -> Unit raise LayoutError

    Set relative widths for the grid columns.

    GridSpec::share_x_mode

    fn GridSpec::share_x_mode(self : GridSpec) -> ShareMode

    Return the sharing mode for x coordinates in this grid.

    GridSpec::share_y_mode

    fn GridSpec::share_y_mode(self : GridSpec) -> ShareMode

    Return the sharing mode for y coordinates in this grid.

    GridSpec::subplot

    fn GridSpec::subplot(self : GridSpec, row_start : Int, row_end : Int, column_start : Int, column_end : Int) -> SubplotSpec raise LayoutError

    Select a half-open row/column span from this grid.

    GridSpec::vspace

    fn GridSpec::vspace(self : GridSpec) -> Double

    GridSpec::width_ratios

    fn GridSpec::width_ratios(self : GridSpec) -> Array[Double]

    Return relative widths for the grid columns.

    GridSpec::with_shared_axes

    fn GridSpec::with_shared_axes(self : GridSpec, share_x : ShareMode, share_y : ShareMode) -> GridSpec

    Return a copy of this grid with explicit x and y sharing constraints.

    Rect

    pub struct Rect {
    x : Double
    y : Double
    width : Double
    height : Double
    }

    A rectangular area. Coordinate units and origin are defined by the producing API: layouts return display pixels; Axes::get_position returns normalized Figure coordinates with a lower-left origin.

    Rect::height

    fn Rect::height(self : Rect) -> Double

    Rect::width

    fn Rect::width(self : Rect) -> Double

    Rect::x

    fn Rect::x(self : Rect) -> Double

    Rect::y

    fn Rect::y(self : Rect) -> Double

    ShareMode

    pub(all) enum ShareMode {
    None
    All
    Row
    Column
    }

    How a regular subplot grid links coordinate axes.

    SubplotSpec

    pub struct SubplotSpec {
    grid : GridSpec
    row_start : Int
    row_end : Int
    column_start : Int
    column_end : Int
    }

    A rectangular span of rows and columns in a GridSpec.

    SubplotSpec::column_end

    fn SubplotSpec::column_end(self : SubplotSpec) -> Int

    SubplotSpec::column_span

    fn SubplotSpec::column_span(self : SubplotSpec) -> (Int, Int)

    Return the inclusive column range occupied by this subplot.

    SubplotSpec::column_start

    fn SubplotSpec::column_start(self : SubplotSpec) -> Int

    Return the selected column span.

    SubplotSpec::get_geometry

    fn SubplotSpec::get_geometry(self : SubplotSpec) -> (Int, Int, Int, Int)

    Return grid dimensions and inclusive flat start/end indices.

    SubplotSpec::get_gridspec

    fn SubplotSpec::get_gridspec(self : SubplotSpec) -> GridSpec

    Matplotlib-compatible name for the owning GridSpec getter.

    SubplotSpec::get_topmost_subplotspec

    fn SubplotSpec::get_topmost_subplotspec(self : SubplotSpec) -> SubplotSpec

    Return the outermost SubplotSpec that contains this nested span.

    SubplotSpec::grid

    fn SubplotSpec::grid(self : SubplotSpec) -> GridSpec

    Return the GridSpec owning this span.

    SubplotSpec::is_first_col

    fn SubplotSpec::is_first_col(self : SubplotSpec) -> Bool

    Return whether this subplot touches the first column of its grid.

    SubplotSpec::is_first_row

    fn SubplotSpec::is_first_row(self : SubplotSpec) -> Bool

    Return whether this subplot touches the first row of its grid.

    SubplotSpec::is_last_col

    fn SubplotSpec::is_last_col(self : SubplotSpec) -> Bool

    Return whether this subplot touches the last column of its grid.

    SubplotSpec::is_last_row

    fn SubplotSpec::is_last_row(self : SubplotSpec) -> Bool

    Return whether this subplot touches the last row of its grid.

    SubplotSpec::rect

    fn SubplotSpec::rect(self : SubplotSpec, figure_width : Int, figure_height : Int, margin : Int) -> Rect

    Compute the display rectangle occupied by this span.

    SubplotSpec::rect_with_bounds

    fn SubplotSpec::rect_with_bounds(self : SubplotSpec, figure_width : Int, figure_height : Int, left : Double, bottom : Double, right : Double, top : Double, wspace? : Double, hspace? : Double) -> Rect

    Compute this span inside normalized figure bounds.

    left, bottom, right, and top are fractions of the figure size, with the same orientation as Matplotlib's subplot parameters. Display coordinates still use the SVG top-left origin, so bottom is converted to a top-down y coordinate here. Figure spacing applies to each nested grid where that grid has not explicitly set its own spacing. wspace is horizontal and hspace vertical, following Matplotlib's parameter names.

    SubplotSpec::row_end

    fn SubplotSpec::row_end(self : SubplotSpec) -> Int

    SubplotSpec::row_span

    fn SubplotSpec::row_span(self : SubplotSpec) -> (Int, Int)

    Return the inclusive row range occupied by this subplot.

    SubplotSpec::row_start

    fn SubplotSpec::row_start(self : SubplotSpec) -> Int

    Return the selected row span.

    SubplotSpec::subgridspec

    fn SubplotSpec::subgridspec(self : SubplotSpec, rows : Int, columns : Int, hspace? : Double, vspace? : Double, width_ratios? : Array[Double], height_ratios? : Array[Double]) -> GridSpec raise LayoutError

    Select a nested grid inside this subplot span.

    The returned GridSpec keeps the parent span in its geometry chain, so a child can be passed directly to Figure::add_subplot after selecting one of its own cells.

    gridspec

    fn gridspec(rows : Int, columns : Int, hspace? : Double, vspace? : Double, width_ratios? : Array[Double], height_ratios? : Array[Double]) -> GridSpec raise LayoutError

    Construct a regular grid. Spacing is measured as a fraction of the cell size. hspace is horizontal and vspace vertical. Omitted values inherit the figure's spacing during layout, falling back to 0.1 for standalone grids.

    rect

    fn rect(x : Double, y : Double, width : Double, height : Double) -> Rect

    Construct a rectangle without imposing coordinate units.

    test {
    let bounds = @gridspec.rect(10.0, 20.0, 30.0, 40.0)
    assert_eq((bounds.x(), bounds.y()), (10.0, 20.0))
    assert_eq((bounds.width(), bounds.height()), (30.0, 40.0))
    }