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.21.0 |
| dear-imgui-rs | 0.21.0 |
| dear-implot-sys | 0.21.0 |
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-v1provider 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-v1) 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-v1 with ImGui + ImPlot)
# 4) Serve and open in a browser
Notes:
- The
dear-imgui-web-democrate inexamples-wasmenablesimplotwhen passed toxtask web-demo implot; it is not a default feature. - This is an early, experimental path; API and build steps may evolve in future releases. For production use, pin to a specific compatible
0.21release 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.
Use compatible stable requirements:
[]
= "0.21"
= "0.21"
use dear_imgui_rs as imgui;
use *;
This backend-free sample builds CPU draw data only. A visible application needs
a platform backend and renderer; use implot_minimal below for that integration.
Managed renderers must consume their normal frame/texture protocol instead of
this CPU-only legacy path.
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.
Migrating live axis links
PlotUi::setup_axis_links and set_next_axis_links now require unsafe, like
their raw-axis variants. ImPlot retains the supplied f64 pointers and writes
back at EndPlot, so a short Rust reference cannot prove their full lifetime.
Keep storage at a stable address without other access until PlotContext is
destroyed, or explicitly clear all stored/pending links. To clear an applied
link, begin the same plot ID, enable the axis, call setup_axis_links with
None, then end that plot. Clear pending next-plot links separately.
EndPlot alone does not unlink every axis: subsequent plots can still write
through a retained secondary-axis pointer. Rejected begin calls and frame
changes do not generally discard pending links. set_next_axis_links targets
the next plot, not the next frame. Follow each method's setup-phase requirements.
Prefer setup_*_axis_limits / set_next_*_axis_limits when live writeback is
unnecessary; these copy values and remain safe.
Validated numeric formats
ImPlot value labels use validated FloatFormat values instead of arbitrary C
format strings. Axis formats additionally use AxisFormat, which enforces
ImPlot's fixed 15-byte storage limit. These formats must be ASCII because
ImPlot forwards the complete string to locale-sensitive native formatting
paths. Use an axis formatter closure when labels need localized or arbitrary
UTF-8 text.
let value_format = new?;
let axis_format = new?;
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.21"
= "0.21"
Basic usage:
use *;
use *;
The following plot snippets assume an initialized renderer-driven frame, an
active plot, and application-owned input arrays. They illustrate API calls;
implot_minimal and implot_showcase are complete runnable applications.
Plot Types
Line and Scatter Plots
// Line plot
new.plot;
// Scatter plot
new.plot;
// Item styling via ImPlotSpec-backed builder helpers
new
.with_line_color // alpha comes from the color itself
.with_line_weight
.with_marker
.with_marker_size
.with_marker_fill_color
.plot;
// The same styling helpers are available on other ImPlotSpec-backed builders
new
.with_fill_color
.with_line_color
.with_line_weight
.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;
// Automatic binning method
new
.with_bins
.plot;
// 2D Histogram
new
.with_bins
.plot;
Heatmaps
let data: = .map.collect;
new
.with_scale
.with_bounds
.try_label_format
.expect
.plot;
Pie Charts
let labels = vec!;
let values = ;
new
.normalize
.exploding
.with_start_angle
.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 multi_plot = new
.add_y_axis
.add_y_axis;
if let Ok = multi_plot.begin
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
let y_axis_format = new.expect;
plot_ui.setup_y_axis_format;
// Apply limits
plot_ui.setup_axes_limits;
// Selection query
if plot_ui.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?;
Universal Plot Builder
For a unified fallible API, use PlotBuilder:
// Line plot
line.build?;
// Bar plot
bar.build?;
// Histogram
histogram.build?;
// Heatmap
heatmap.build?;
Error Handling
PlotBuilder::build and the fallible PlotUi helpers return Result<(), PlotError>.
The Plot::plot trait method returns () and skips invalid data; call validate()
first when the application needs an error:
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:
examples/03-features/implot_minimal.rs- Minimal plot integration.examples/03-features/implot_showcase.rs- Plot gallery, subplots, and dynamic data.
cargo run -p dear-imgui-examples --bin implot_minimal --features implot
cargo run -p dear-imgui-examples --bin implot_showcase --features implot
Building
This crate requires:
- Rust 1.92 or later (the workspace minimum).
- A C++17 compiler for default native source builds.
- Initialized recursive submodules when building from a Git checkout.
CMake is optional: IMPLOT_SYS_USE_CMAKE requests its alternate source route,
which can fall back to the maintained cc route when an upstream wrapper needs
a repository patch. Ordinary builds use validated checked-in Rust bindings and
do not require libclang. Explicit regeneration requires bindgen and libclang.
The build process automatically handles:
- Compiling the pinned ImPlot and cimplot sources.
- Validating checked-in binding provenance.
- Linking to the shared Dear ImGui core supplied by
dear-imgui-sys.
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
The Rust crate is licensed under MIT OR Apache-2.0, matching the workspace. The pinned ImPlot/cimplot sources retain their upstream license notices.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.