Overview
TheLayout struct controls axis ranges, tick formatting, labels, themes, and all visual properties except plot-specific colors and sizes.
Creating Layouts
Automatic Layout
The recommended approach isLayout::auto_from_plots(), which inspects plot types and data:
auto_from_plots() automatically computes (src/render/layout.rs:213-544):
- Axis ranges by examining plot bounds with smart padding
- Tick count based on plot dimensions
- Categorical labels for bar, box, violin plots
- Legend presence when plots have
.with_legend() - Colorbar presence for heatmaps and color-encoded plots
- Grid visibility (disabled for Manhattan, UpSet plots)
Manual Layout
For full control, construct a layout with explicit ranges:Axis Configuration
Axis Ranges
Log Scale
Tick Configuration
Tick Formatting
TheTickFormat enum (src/render/layout.rs:10-50) controls how axis values are displayed:
Built-in Formats
Custom Formatters
Per-Axis Formatting
Categorical Axes
For bar, box, violin plots,auto_from_plots() automatically detects categorical axes:
Labels and Titles
Twin Y-Axes
For plots with two Y-axes:Dimensions
Legend and Colorbar
Legend
Colorbar
auto_from_plots() automatically adds a colorbar for plots with continuous color mappings (Heatmap, Histogram2D, filled Contour, color-encoded DotPlot).
Colorbar width is fixed at 85 pixels (20px bar + 50px labels + 15px gap) in the right margin.
Annotations
Reference Lines
Shaded Regions
Text Annotations
Font Configuration
Themes and Palettes
Advanced Features
DateTime Axes
Rotated Tick Labels
Axis Clamping
Terminal Backend Optimization
ComputedLayout
TheComputedLayout struct (src/render/layout.rs:785-1030) is derived from Layout during rendering and includes:
- Final computed dimensions with margins
- Adjusted axis ranges (after nice rounding)
- Coordinate mapping functions (
map_x,map_y,map_y2)
ComputedLayout directly; it’s used internally by the rendering pipeline.
Source Code References
- Layout struct:
src/render/layout.rs:88-152 - Auto-detection logic:
src/render/layout.rs:213-544 - TickFormat enum:
src/render/layout.rs:10-50 - ComputedLayout:
src/render/layout.rs:785-1030
Next Steps
- Theme System - Visual styling
- Architecture Overview - Rendering pipeline
- Annotations Guide - Advanced annotation techniques