GPU-accelerated rendering backend for matplotplusplus using wgpu.
- 🚀 GPU-Accelerated - Hardware-accelerated rendering via wgpu
- 🦀 Rust Wrapper - Safe, Object-Oriented Rust API (
Figure,Axes) - 🎨 Matplotlib-like API - Familiar syntax (
plot,scatter,bar,hist) - 💻 Cross-platform - Windows, Linux, macOS, WASM support
- ⚡ High Performance - Batched rendering, optimized for large datasets
matplotplusplus (C++) ← Plotting library (all plot types)
↓
WgpuBackend ← This project: GPU backend
↓
WgpuRenderer ← Abstract interface
↓
Your Implementation ← PrimitiveRenderer, TextRenderer
Components:
- C++ Backend - Implements matplot++
backend_interface - C FFI Layer - C API for language bindings
- Rust Bindings - Safe, idiomatic Rust wrapper
mpl-wgpu/
├── src/ # Source code
│ ├── c_api.cpp/h # C API wrapper implementation
│ ├── ffi.rs # Rust FFI bindings
│ ├── plotting.rs # Safe, Object-Oriented Rust wrappers
│ └── ... # Backend implementation
├── examples/
│ ├── cpp/ # C++ examples
│ └── rust/ # Rust examples
├── vendor/matplotplusplus/ # Git submodule
└── tests/ # Unit tests
mkdir build && cd build
cmake ..
cmake --build .cargo build --release#include <matplot/backend/wgpu_backend.h>
#include <matplot/matplot.h>
// Implement WgpuRenderer for your GPU setup
class MyRenderer : public matplot::backend::WgpuRenderer {
// ... implement draw methods ...
};
int main() {
auto renderer = std::make_shared<MyRenderer>();
auto backend = std::make_shared<matplot::backend::WgpuBackend>(
renderer
);
auto fig = matplot::figure();
fig->backend(backend);
matplot::plot({1, 2, 3}, {1, 4, 9});
fig->draw();
}use mpl_wgpu::plotting::{PlotBackend}; // PlotBackend manages the figure context
// Example usage within a rendering loop (e.g. winit)
fn draw_frame(backend: &mut PlotBackend) {
// Access the Figure and Axes
let fig = backend.figure();
let ax = fig.current_axes();
// Plot data using standard Matplotlib style strings
ax.plot(&[1.0, 2.0, 3.0], &[1.0, 4.0, 9.0], "-o");
// Configure plot
ax.set_title("Hello from Rust!");
ax.grid(true);
}
// See examples/rust/ for full application structure.This backend is designed to be contributed upstream to matplotplusplus:
- Minimal dependencies (matplot++, webgpu.hpp)
- Abstract renderer interface
- Well-documented, tested code
- Google C++ style guide compliant
MIT License - see LICENSE for details
- matplotplusplus - Plotting library
- wgpu - GPU API implementation