plotly/plotly_subplots

Source   Edit  

Types

Grid = object
  layout*: Layout
  numPlotsPerRow*: int
Source   Edit  

Procs

proc `[]`(grid: Grid; coord: tuple[row, col: int]): PlotJson {....raises: [],
    tags: [], forbids: [].}
returns the plot at (row, column) coordinate coord. NOTE: the plot is returned as a PlotJson object, not as the Plot[T] originally put in! Source   Edit  
proc `[]`(grid: Grid; idx: int): PlotJson {....raises: [], tags: [], forbids: [].}
returns the plot at index idx. NOTE: the plot is returned as a PlotJson object, not as the Plot[T] originally put in! Source   Edit  
proc `[]=`[T](grid: var Grid; coord: tuple[row, col: int]; plt: Plot[T])
converts the given Plot[T] to a PlotJson and assigns to specified (row, column) coordinate of the grid. Source   Edit  
proc `[]=`[T](grid: var Grid; idx: int; plt: Plot[T])
converts the given Plot[T] to a PlotJson and assigns to the given index. Source   Edit  
proc add[T](grid: var Grid; plt: Plot[T])
add a new plot to the grid. Extends the number of plots stored in the Grid by one. NOTE: the given Plot[T] object is converted to a PlotJson object upon assignment! Source   Edit  
proc convertDomain(d: Domain | DomainAlt): Domain
proc to get a Domain from either a Domain or DomainAlt tuple. That is a tuple of: left, bottom, right, top notation to: left, bottom, width, height Source   Edit  
proc createGrid(numPlots: int; numPlotsPerRow = 0; layout = Layout()): Grid {.
    ...raises: [], tags: [], forbids: [].}
creates a Grid object with numPlots to which one can assign plots at runtime. Optionally the number of desired plots per row of the grid may be given. If left empty, the grid will attempt to produce a square, resorting to more columns than rows if not possible. Optionally a base layout can be given for the grid. Source   Edit  
proc createGrid(size: tuple[rows, cols: int]; layout = Layout()): Grid {.
    ...raises: [], tags: [], forbids: [].}
creates a Grid object with rows x cols plots to which one can assign plots at runtime. Optionally a base layout can be given for the grid. Source   Edit  
proc toPlotJson(grid: Grid): PlotJson {....raises: [KeyError], tags: [],
                                        forbids: [].}
converts the Grid object to a PlotJson object ready to be plotted via the normal show procedure. Source   Edit  

Macros

macro subplots(stmts: untyped): untyped
macro to create subplots from several Plot[T] objects the macro needs to contain the blocks baseLayout and one or more plot blocks. A plot block has the Plot[T] object in line 1, followed by the domain description of the subplot, i.e. the location within the whole canvas.

let plt1 = scatterPlot(x, y) # x, y some seqT let plt2 = scatterPlot(x2, y2) # x2, y2 some other seqT let layout = Layout(...) # some layout for the whole canvas let subplt = subplots: baseLayout: layout plot: plt1 left: 0.0 bottom: 0.0 width: 0.45 height: 1.0 # alternatively use right, top instead of width, height # single letters also supported, e.g. l == left plot: plt2 # or just write a concise tuple, here the (0.55, 0.0, 0.45, 1.0)

will create a subplot of plt1 on the left and plt2 on the right. This simply creates the following call to combine. let subplt = combine(layout, plt1.toPlotJson, plt2.toPlotJson, (left: 0.0, bottom: 0.0, width: 0.45, height: 1.0), (left: 0.55, bottom: 0.0, width: 0.45, height: 1.0))

Source   Edit