Dear ImPlot - Rust Bindings
High-level Rust bindings for ImPlot, the immediate mode plotting library. This crate provides safe, idiomatic Rust bindings designed to work seamlessly with dear-imgui-rs (which uses cimgui C API) and dear-implot-sys (which uses cimplot C API).
For native build/link options (source, system/prebuilt, remote prebuilt), see extensions/dear-implot-sys/README.md.
Links
- Upstream: https://github.com/epezent/implot
- C API: https://github.com/cimgui/cimplot
Compatibility
| Item | Version |
|---|---|
| Crate | 0.8.x |
| dear-imgui-rs | 0.8.x |
| dear-implot-sys | 0.8.x |
WASM (WebAssembly) support
This crate has experimental support for wasm32-unknown-unknown targets via the same import-style design used by the core ImGui bindings:
dear-implot+dear-implot-sysexpose awasmfeature which:- Enables import-style FFI that links against the shared
imgui-sys-v0provider module. - Avoids compiling C/C++ during the Rust build for wasm.
- Enables import-style FFI that links against the shared
- The provider module (
imgui-sys-v0) is built once using Emscripten and contains:- Dear ImGui + cimgui (from
dear-imgui-sys) - ImPlot + cimplot (from
dear-implot-sys)
- Dear ImGui + cimgui (from
To try the web demo with ImPlot enabled:
# 1) Generate pregenerated wasm bindings (Dear ImGui core + ImPlot)
# 2) Build the main wasm + JS (includes ImPlot demo window)
# 3) Build the provider (Emscripten imgui-sys-v0 with ImGui + ImPlot)
# 4) Serve and open in a browser
Notes:
- The
dear-imgui-web-democrate inexamples-wasmenables theimplotfeature by default, so the “ImPlot (Web)” window is shown when ImPlot bindings + provider are available. - This is an early, experimental path; API and build steps may evolve in future releases. For production use, pin to a specific
0.6.xrelease and follow changes indocs/WASM.md.
See also: docs/COMPATIBILITY.md for the full workspace matrix.
Integration Quickstart
This crate integrates with dear-imgui-rs directly — add both crates, then build plots inside an ImGui window using a PlotContext bound to the current ImGui context.
[]
= "0.8"
= "0.8"
use dear_imgui as imgui;
use *;
Notes:
- Base ImGui static library linking is handled by
dear-imgui-sys; you do not need to link it here. - Refer to the
-sysREADME forIMPLOT_SYS_*env vars when using prebuilt libraries.
Features
- Safe, idiomatic Rust API - Memory-safe interfaces with proper lifetime management
- Full compatibility with dear-imgui - Uses the same context management patterns
- Builder pattern for plots - Fluent, ergonomic API for creating plots
- Comprehensive plot types - Support for all major plot types including:
- Line plots and scatter plots
- Bar charts and histograms (1D and 2D)
- Heatmaps and pie charts
- Error bars and shaded plots
- Stem plots and more
- Advanced features - Subplots, multi-axis plots, and legend management
- Modular design - Each plot type is in its own module for better organization
- Universal plot builder - Unified API for creating any plot type
Quick Start
Add to your Cargo.toml:
[]
= "0.8"
= "0.8"
Basic usage:
use *;
use *;
Plot Types
Line and Scatter Plots
// Line plot
new.plot;
// Scatter plot
new.plot;
Bar Charts
// Simple bar chart
new
.with_bar_size
.plot;
// Positional bar chart
new
.with_bar_size
.plot;
Histograms
// 1D Histogram
new
.with_bins
.density
.cumulative
.plot;
// 2D Histogram
new
.with_bins
.plot;
Heatmaps
let data: = .map.collect;
new
.with_scale
.with_bounds
.with_label_format
.plot;
Pie Charts
let labels = vec!;
let values = ;
new
.normalize
.exploding
.with_angle0
.plot;
Error Bars
let errors = ;
new
.horizontal
.plot;
Shaded Plots
// Shaded area plot
new
.with_y_ref
.plot;
// Shaded between two curves
new
.plot;
Advanced Features
Subplots
if let Ok = new
.with_size
.with_flags
.begin
Multi-Axis Plots
let mut multi_plot = new
.add_y_axis
.add_y_axis;
if let Ok = multi_plot.begin
Universal Plot Builder
Axis Setup & Selection
// Inside an active plot (between begin_plot/end)
// Configure axes labels/flags
plot_ui.setup_axes;
// Set explicit ticks on X1
let tick_pos = ;
let tick_lbl = ;
plot_ui.setup_x_axis_ticks_positions;
// Format Y1 ticks
plot_ui.setup_y_axis_format;
// Apply limits
plot_ui.setup_axes_limits;
// Selection query
if is_plot_selected
Infinite Lines & Image
// Infinite lines
plot_ui.inf_lines_vertical?;
plot_ui.inf_lines_horizontal?;
// Image plot (using ImTextureID)
let bounds_min = ImPlotPoint ;
let bounds_max = ImPlotPoint ;
plot_ui.plot_image?;
For a more unified API, you can use the PlotBuilder:
// Line plot
line.build?;
// Bar plot
bar.build?;
// Histogram
histogram.build?;
// Heatmap
heatmap.build?;
Error Handling
All plot functions return Result<(), PlotError> for proper error handling:
match new.validate
Integration with Dear ImGui
This crate is designed to work seamlessly with the dear-imgui ecosystem:
- Uses the same context management patterns as dear-imgui
- Compatible with dear-imgui's UI tokens and lifetime management
- Shares the same underlying Dear ImGui context
- Follows the same safety and ergonomics principles
Examples
See the examples/ directory for complete working examples:
plot_gallery.rs- Comprehensive showcase of all plot typesadvanced_features.rs- Subplots and multi-axis examplesreal_time_plotting.rs- Dynamic data visualization
Building
This crate requires:
- Rust 1.70 or later
- C++ compiler (for building ImPlot)
- CMake (for building dependencies)
The build process automatically handles:
- Building ImPlot from source
- Generating C++ wrapper functions
- Linking with dear-imgui
Architecture
This crate follows the same architectural patterns as dear-imgui-rs:
- Context Management: Separate ImPlot context that works alongside Dear ImGui
- Lifetime Safety: Plot tokens ensure proper begin/end pairing
- RAII: Automatic cleanup of resources and style stacks
- Builder Patterns: Fluent APIs for configuration
- Modular Design: Each plot type is in its own module
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.