Figure API allows you to create complex multi-panel layouts with multiple plots arranged in a grid, supporting merged cells, shared axes, and shared legends.
Basic Grid Layout
Creating a Simple Grid
The simplest figure is a regular grid where each cell contains one plot:Panel Labels
Add automatic panel labels (A, B, C, …) to identify subplots:Customizing Panel Labels
Merged Panels
Create irregular layouts by merging cells.Wide Panel (Spanning Columns)
Tall Panel (Spanning Rows)
Grid Cell Indexing
Cells are numbered left-to-right, top-to-bottom:Shared Axes
Share axis scales across rows or columns for easier comparison.Shared Y Axis Per Row
Shared X Axis Per Column
Custom Shared Axis Configuration
Shared Legend
Collect legend entries from all panels into a single shared legend:- Collects all unique legend labels across panels
- Places the legend in the top-right corner of the figure
- Removes individual panel legends to avoid duplication
Custom Legend Position
Figure Sizing
Cell Size (Default)
Set the size of each individual cell:- Width:
cell_width × columns + margins - Height:
cell_height × rows + margins
Fixed Figure Size
Set the total figure dimensions and let cells auto-size:Figure Title
Add a title above the entire figure:Complete Example
Here’s a comprehensive example combining multiple features:Figure API Reference
Key methods onFigure:
| Method | Description |
|---|---|
new(rows, cols) | Create a new figure with a grid |
with_plots(Vec<Vec<Plot>>) | Set the plots for each panel |
with_layouts(Vec<Layout>) | Set the layout for each panel |
with_structure(Vec<Vec<usize>>) | Define merged cells (default: regular grid) |
with_labels() | Add panel labels (A, B, C, …) |
with_label_config(LabelConfig) | Customize panel labels |
with_title(String) | Add a figure title |
with_title_size(u32) | Set title font size |
with_cell_size(width, height) | Set individual cell dimensions |
with_figure_size(width, height) | Set total figure dimensions |
with_shared_x(row) | Share X axis for a row |
with_shared_y(col) | Share Y axis for a column |
with_shared_axis(SharedAxis) | Custom shared axis configuration |
with_shared_legend() | Collect legends into one shared legend |
with_legend_position(pos) | Position the shared legend |
with_theme(Theme) | Apply a theme to all panels |
render() | Render the figure to a Scene |
Best Practices
Use consistent color schemes across panels
Use consistent color schemes across panels
When showing the same groups in multiple panels, use the same colors for each group throughout the figure.
Share axes when comparing across panels
Share axes when comparing across panels
Add panel labels for clarity
Add panel labels for clarity
Always use
.with_labels() so you can reference panels unambiguously (e.g., “Panel B shows…”).Use a shared legend when possible
Use a shared legend when possible
Keep panel sizes reasonable
Keep panel sizes reasonable
- Aim for 300-500 pixels per cell for most use cases
- Make panels larger (500-700 px) for detailed plots
- Make panels smaller (200-300 px) for many-panel overviews
Next Steps
- Annotations - Adding reference lines, shaded regions, and text
- Styling & Customization - Themes, colors, and visual styles