Charton - A versatile plotting library for Rust
Altair-style declarative plotting for Rust. High-performance, Polars-native, and Wasm-ready.
"Really nice project. ... This works perfectly as an ecosystem." — Ritchie Vink, Creator of Polars
Charton is a high-performance Rust plotting library featuring a declarative API inspired by Altair. It provides native Polars support and bridges the gap to the Python visualization ecosystem (Altair/Matplotlib). Integrated with evcxr_jupyter, it enables seamless interactive data exploration in notebooks.
Installation
Add to Cargo.toml:
[]
= "0.4"
= "0.49"
Quick Start
Charton provides a high-level, declarative API for Polars. Standard visualizations can be generated using a concise one-liner syntax:
// Data preparation: Hooke's Law (Force vs. Extension)
let df = df!?;
// One-liner plotting
build?.mark_point?.encode?.save?;
Layered Grammar
Inspired by the Grammar of Graphics (as seen in ggplot2 and Altair), Charton replaces rigid templates with a modular, layer-based system. Visualizations are constructed by stacking atomic marks, offering infinite flexibility beyond fixed chart types.
// Create individual layers
let line = build?
.mark_line?
.encode?;
let point = build?
.mark_point?
.encode?;
// Combine into a composite chart
line.and.save?;
Charton can also leverages Rust’s functional paradigms, enabling infinite layer composition via fluent chaining or iterator folding. This allows for effortless, dynamic generation of complex multi-layered plots.
let layers: = vec!;
// Equivalent to line.and(point).and(bar)...
let lc = layers.into_iter
.reduce
.expect;
Interactive Notebooks (Jupyter)
Charton integrates with evcxr_jupyter for interactive data exploration. Replacing .save() with .show() renders SVGs directly within notebook cells:

WebAssembly and Frontend
Charton supports WebAssembly and modern web frontend; please refer to Charton Docs for details.
Industrial-Grade Visualization
Charton scales the Grammar of Graphics to heavy-duty production. By adopting the same proven philosophy as ggplot2, Altair, and the evolving ECharts, it validates its architecture as the industry standard, delivering strict type safety and zero-copy Polars integration for robust pipelines under extreme loads. This is powered by a rigorous Scale Arbitration engine that consolidates data domains into a "Single Source of Truth," ensuring absolute mathematical consistency and seamless cross-plot mapping while eliminating the fragile, hard-coded patches and silent overrides common in template-based tools.
This figure demonstrates semantic synchronization in Charton. Heterogeneous samples (point layer) are anchored to a global background (bar layer). By enforcing a single mathematical truth across all layers, Charton maintains absolute color consistency, ensuring samples are accurately contextualized within the global background.
Publish Quality
Designed for precision, Charton provides pixel-perfect control over complex marks. Whether it is a multi-layered ErrorBar for medical research or a high-density scatter plot for bioinformatics, Charton delivers the aesthetic rigor required by top-tier journals like Nature, Science, and Cell.
Performance Benchmark
Benchmarks are currently in progress.
Documentation
Please go to the Charton Docs for full documentation.
Contributions Welcome
Contributions are welcome! Whether it's improving documentation, adding new chart types, or optimizing performance, your help is appreciated.
License
Charton is licensed under the Apache License 2.0.
Acknowledgements
- AI Collaboration: This project was developed based on a human-led architectural design, with AI tools (including Qwen, Kimi, ChatGPT, Gemini, and others) serving as intelligent pair-programmers. While AI assisted in accelerating the implementation through boilerplate generation and API exploration, all core logic, architectural decisions, and final implementations were strictly audited, refined, and verified by the author.
- Personal Support: I would like to thank my family for their support, providing the time and environment needed to bring this project to life.
Note: This project is developed independently and is not affiliated with or endorsed by any organization.