Lilaq Documentation

website·Indexed 32 days ago

https://lilaq.org

A plotting library for Typst featuring a variety of built-in plot types including scatter, bar, boxplot, violin, contour, and colormesh. The library provides comprehensive tools for creating diagrams with customizable axes, grids, legends, and styling options.

Tokens
37K
Snippets
158
Records
297
Agent score
62%

What's inside Lilaq

  1. Overview of Lilaq plotting library for Typst

    Lilaq is a plotting library designed for Typst that produces publication-ready graphics with real-time previews. It features seamless integration with Typst documents and consistent styling interoperability with the Zero package.
  2. Draw geometric primitives in Lilaq

    Lilaq provides several geometric primitives for drawing custom shapes beyond conventional plot types. These include line (for lines and arrows), rect (for rectangles), ellipse (for ellipses), and path (for arbitrary Bézier splines). Additionally, the place primitive can be used to overlay any content on top of a diagram.
  3. Use plot grids (subplots) in Lilaq 0.6.0

    Lilaq version 0.6.0 introduces support for plot grids, allowing users to create subplots for more flexible data visualization.
  4. Use plot grids (subplots) in Lilaq 0.6.0

    Lilaq version 0.6.0 introduces support for plot grids, allowing users to create subplots for more flexible data visualization.
  5. Use accessibility-focused color maps from lq.color.map

    The lq.color.map module provides a curated selection of color maps designed for scientific application. All featured maps are perceptually uniform, perceptually ordered, and CVD (color-vision deficiency) friendly.

    Available map categories include:

    • Sequential: For data that varies from low to high.
    • Diverging: For data that varies from a center point in two opposite directions.
    • Bi-sequential: Specialized combinations (e.g., tovu, which combines topo and bukavu).
    • Qualitative: Best used for style cycles where distinct categories are needed.

    Notable maps include viridis, magma, plasma, and inferno (from Matplotlib), and cividis (an optimization of viridis for better perceptual linearity for those with CVD).

  6. Use plot grids (subplots) in Lilaq 0.6.0

    Lilaq 0.6.0 introduces support for plot grids, allowing users to create subplots for more complex data visualizations.
  7. Create a colorbar for a plot using lq.colorbar

    The lq.colorbar function creates a visual representation of the color mapping used in a plot instance (such as scatter, colormesh, contour, or quiver). It generates a slim diagram containing a filled gradient based on the plot's color map, appropriate ticks, and an optional label. Because the colorbar is a separate inline object, it can be placed anywhere in the document. To ensure the colorbar matches the height of the associated plot, it is recommended to use a lq.set-diagram rule to set a consistent height for both.
    #show: lq.set-diagram(height: 3.5cm, width: 4cm)
    
    #let mesh = lq.colormesh(
      lq.linspace(-0.3, 1.3),
      lq.linspace(-0.3, 1.3),
      (x, y) => x * y,
      map: gradient.linear(..color.map.icefire).sharp(9)
    )
    
    #lq.diagram(mesh)
    #lq.colorbar(mesh, thickness: 2mm)
  8. Create a custom scale using lq.scale.scale

    The lq.scale.scale function is a constructor used to define how data coordinates are transformed into scaled coordinates. This is essential for visualizing data, such as implementing linear or logarithmic scales to improve readability of large ranges. The transformation function should focus on the mapping logic rather than absolute coefficients or offsets (e.g., for a linear scale, use x => x instead of x => a * x + b).
    // Example: Creating a linear scale
    let linear_scale = lq.scale.scale(
      transform: x => x,
      inverse: x => x
    )
    
    // Example: Creating a logarithmic scale
    let log_scale = lq.scale.scale(
      transform: x => calc.log(x),
      inverse: x => calc.exp(x),
      identity: 1
    )
  9. Create plot grids (subplots) using lq.layout

    Lilaq 0.6.0 introduces native support for plot grids (subplots) implemented via show rules using the lq.layout function.
    // Use lq.layout in a show rule to define a plot grid
  10. Align diagrams in a grid using lq.layout

    The lq.layout function applies special show rules that ensure diagrams placed within a Typst grid are aligned as cells. The alignment algorithm ensures that horizontal and vertical axis spines line up across rows and columns, regardless of axis labels, ticks, titles, or legends. This alignment is maintained even when a diagram spans multiple rows or columns.
    #show: lq.set-diagram(width: 4cm, height: 2.2cm)
    
    #figure({
      show: lq.layout // Applies the special alignment layout rule
    
      grid(
        columns: 2,
        row-gutter: 1em,
        column-gutter: 1em,
        lq.diagram(
          lq.plot((1, 2, 3), (3, 2, 5)),
          lq.plot((1, 2, 3), (4, 4.5, 3)),
        ),
        lq.diagram(
          lq.bar((1, 2, 3), (3, 2, 5))
        ),
        lq.diagram(
          lq.plot((5, 7, 8, 9), (2, 3, 3, 4))
        ),
        lq.diagram(
          lq.bar((1, 2, 3), (11, 1, 4))
        ),
      )
    })
    
  11. Create a diagram with lq.diagram

    The lq.diagram function creates a container for one or more plots. All plots must be wrapped in a diagram to be displayed. It allows configuration of the overall dimensions, titles, axis labels, scales, and grid settings.
    #lq.diagram(
      title: [Trigonometric Functions],
      xlabel: $x$,
      ylabel: $y$,
      lq.plot(lq.linspace(0, 10), calc.sin),
      lq.plot(lq.linspace(0, 10), x => calc.cos(x) / 2)
    )