esoc-chart
High-level charting library for Rust. Built on esoc-gfx and designed as a matplotlib-equivalent for ML workflows.
Gallery
Quick Start
[]
= "0.1"
use scatter;
API Levels
esoc-chart provides three levels of abstraction:
Express API
One-liner functions for common chart types. Every builder supports .title(), .x_label(), .y_label(), .size(), .theme(), .to_svg(), and .save_svg().
use *;
// Scatter plot with category coloring
scatter
.color_by
.title
.save_svg?;
// Bar chart
bar
.title
.save_svg?;
// Histogram with custom bin count
histogram
.bins
.title
.save_svg?;
// Grouped and stacked bars
grouped_bar
.title
.save_svg?;
stacked_bar
.title
.save_svg?;
// Pie and donut
pie_labeled
.title
.save_svg?;
pie_labeled
.donut
.save_svg?;
// Box plot, area, heatmap, treemap
boxplot.save_svg?;
area.save_svg?;
heatmap.annotate.save_svg?;
treemap.save_svg?;
Grammar of Graphics API
Composable Chart / Layer system for full control. Combine multiple marks, apply statistical transforms, and use annotations.
use Chart;
use ;
use Stat;
use Annotation;
// Multi-series line chart
let chart = new
.layer
.layer
.title
.x_label
.y_label
.size;
chart.save_svg_to?;
// Scatter with LOESS trend line
let chart = new
.layer
.layer
.title
.annotate;
Scene Graph
Direct access to the underlying esoc-scene scene graph for advanced customization. Charts compile down to esoc_scene::SceneGraph, which renders through esoc-gfx.
Chart Types
| Type | Express function | Mark |
|---|---|---|
| Scatter | scatter() |
Point |
| Line | line() |
Line |
| Bar | bar() |
Bar |
| Grouped Bar | grouped_bar() |
Bar + Dodge |
| Stacked Bar | stacked_bar() |
Bar + Stack |
| Horizontal Bar | grammar API + CoordSystem::Flipped |
Bar |
| Histogram | histogram() |
Bar + Bin |
| Area | area() |
Area |
| Box Plot | boxplot() |
Bar + BoxPlot |
| Pie | pie_labeled() |
Arc |
| Donut | pie_labeled().donut(0.5) |
Arc |
| Heatmap | heatmap() |
Heatmap |
| Treemap | treemap() |
Treemap |
Statistical Transforms
Apply transforms via Layer::stat():
Stat::Bin { bins }-- histogram binning with pretty breaksStat::BoxPlot-- quartiles, whiskers, outliersStat::Smooth { bandwidth }-- LOESS local regressionStat::Aggregate { func }-- count, sum, mean, median, min, max
Themes
Three built-in themes, fully customizable:
use NewTheme;
// Built-in themes
light // white background, gray grid (default)
dark // dark background, muted grid
publication // clean serif font, no grid
// Apply to any chart
scatter
.theme
.save_svg?;
Themes control background, foreground, grid, palette, typography, and mark sizing.
Annotations
Add reference lines, bands, and text labels:
use Annotation;
let chart = scatter
.build
.annotate
.annotate
.annotate
.annotate;
Express builders also support .hline() and .vline() directly.
Faceting
Split data into small multiples:
scatter
.facet_wrap // 2 columns
.save_svg?;
Position Adjustments
Control how overlapping marks are arranged:
Position::Stack-- stack bars/areas verticallyPosition::Dodge-- place side by sidePosition::Fill-- normalize to 100%Position::Jitter { x_amount, y_amount }-- add random displacement
Output Formats
// SVG string
let svg: String = chart.to_svg?;
// Save to file
chart.save_svg_to?;
// PNG (requires `png` feature)
chart.save_png_to?;
Features
| Feature | Description |
|---|---|
png |
Enable PNG output (via esoc-gfx) |
scry-learn |
ML integration: confusion matrices, ROC curves, dataset scatter |
scry-learn Integration
With the scry-learn feature, plot ML results directly:
use *;
// From a trained model's confusion matrix
let svg = confusion_matrix.to_chart.to_svg?;
// ROC curve from predictions
let svg = roc_curve_figure?.to_svg?;
// Scatter a dataset with class coloring
let svg = scatter_dataset?.to_svg?;
Examples
Run the gallery to see all chart types rendered to an HTML page:
Individual examples:
License
MIT OR Apache-2.0