Installation
Add Kuva to yourCargo.toml:
Feature Flags
| Feature | Description |
|---|---|
png | Enables PNG output via resvg (rasterized from SVG) |
pdf | Enables PDF output via svg2pdf |
cli | Enables the kuva CLI binary |
full | Enables both png and pdf |
The Prelude Module
The prelude module provides convenient re-exports of the most commonly used types. Import it at the top of your file:- Plot types:
ScatterPlot,LinePlot,BarPlot,Histogram,BoxPlot,ViolinPlot,PiePlot,Heatmap, etc. - Layout & rendering:
Layout,Plot,render_to_svg,render_to_png,render_to_pdf - Figure API:
Figurefor multi-plot layouts - Styling:
Theme,Palette,MarkerShape,LineStyle - Annotations:
TextAnnotation,ReferenceLine,ShadedRegion - Backends:
SvgBackend,PngBackend,PdfBackend,TerminalBackend
Basic Rendering Pipeline
Kuva follows a four-step pipeline:Step-by-Step Example
Create a Layout with customization
Layout::auto_from_plots() automatically determines axis ranges from your data.One-Shot Rendering
For quick plots, use the convenience functions that collapse all steps into one call:Common Patterns
Multiple Series
Combine multiple plots by collecting them into the plots vector:Iterating from Data
Generate plots programmatically from collections:Combining Plot Types
Mix different plot types in the same figure:Advanced Rendering
For fine-grained control, use the rendering functions directly:Special Rendering Functions
Some plot types have dedicated rendering functions:Error Handling
PNG and PDF rendering returnResult<Vec<u8>, String>:
Terminal Output
Render plots directly to the terminal using Unicode characters:Next Steps
- CLI Usage - Using the command-line interface
- Styling & Customization - Themes, colors, and visual styles
- Multi-Plot Figures - Creating complex layouts with the Figure API