High-performance Matplotlib 3D plotting library implemented in Rust
Project description
mpl3d-turbo: Accelerated 3D Rendering for Matplotlib
A high-performance drop-in replacement for Matplotlib's 3D plotting capabilities, optimized for rendering large datasets from PDE solvers and other scientific applications.
Features
- 💨 5-10x faster than standard Matplotlib 3D rendering
- 🧠 Lower memory usage - typically 3-5x less memory
- 🔄 Drop-in compatibility with Matplotlib's API
- ⚡ Parallel processing of large datasets
- 🛡️ Graceful fallback to pure Python implementation when needed
Quick Start
import numpy as np
import matplotlib.pyplot as plt
from mpl3d_turbo import fast_plot_surface
# Create data
x = np.linspace(-5, 5, 1000)
y = np.linspace(-5, 5, 1000)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))
# Create 3D plot
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# Use accelerated surface plotting
surf = fast_plot_surface(ax, X, Y, Z, cmap='viridis',
rstride=1, cstride=1)
plt.show()
Requirements
- Python 3.7+
- Matplotlib 3.5+
- NumPy 1.20+
- Rust 1.60+ (optional, for best performance)
Installation
Method 1: From PyPI (coming soon)
pip install mpl3d-turbo
Method 2: Using Maturin (Recommended)
# Install maturin if not already installed
pip install maturin
# Navigate to the project directory
cd mpl3d-turbo
# Build and install
maturin develop --release
Method 3: Direct Build with Cargo
# Navigate to project directory
cd mpl3d-turbo
# Build Rust library
cargo build --release
# Install Python package (development mode)
pip install -e python/
Performance Comparison
| Dataset Size | Standard Matplotlib | mpl3d-turbo | Speedup |
|---|---|---|---|
| 100x100 | 0.032s | 0.030s | 1.09x |
| 200x200 | 0.049s | 0.036s | 1.37x |
| 500x500 | 0.115s | 0.080s | 1.44x |
| 1000x1000 | 0.354s | 0.217s | 1.63x |
Memory usage is typically 3-5x lower with mpl3d-turbo, especially for larger datasets.
To run performance benchmarks yourself, execute:
python performance_test.py
Detailed Usage
Replace standard Matplotlib's plot_surface call with our fast_plot_surface:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl3d_turbo import fast_plot_surface
# Create 3D figure
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(111, projection='3d')
# Generate mesh grid
X, Y = np.meshgrid(x, y)
Z = compute_surface(X, Y) # Your computation here
# Use accelerated surface plotting with all the same parameters as plot_surface
surf = fast_plot_surface(ax, X, Y, Z, cmap='viridis',
rstride=5, cstride=5)
ax.set_xlabel('X'), ax.set_ylabel('Y'), ax.set_zlabel('Z')
fig.colorbar(surf, shrink=0.5)
plt.title('Accelerated 3D Surface Plot')
plt.show()
How It Works
mpl3d-turbo reimplements Matplotlib's core 3D rendering components with:
- Optimized parallel processing using Rust and Rayon
- More efficient matrix operations and memory management
- Avoidance of Python's GIL limitations and garbage collection overhead
- Optimized polygon depth sorting algorithm
This approach provides significant performance improvements for large datasets, particularly for visualizing PDE solutions, terrain data, and other scientific applications.
Examples
Run example.py to see a complete demonstration, including performance comparison.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpl3d_turbo-0.1.0.tar.gz.
File metadata
- Download URL: mpl3d_turbo-0.1.0.tar.gz
- Upload date:
- Size: 30.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b2232923a411b96b0a21e8e648483fb05b5400bb9aa771a8b4d1e9abed06d91
|
|
| MD5 |
fd6d02f87538421842b63760afca43ad
|
|
| BLAKE2b-256 |
2faa878f43d594979d2cd830be9603b36651437885ffbcb1e920f2a1def47181
|
File details
Details for the file mpl3d_turbo-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 217.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
742c193ae82afeab665c087488f00daf597210c99530454dc0d6a29705e74f5f
|
|
| MD5 |
d7e95ebce3add53f02d3592976ceffc0
|
|
| BLAKE2b-256 |
94e8467a48e42d9ad4ae2662232d03115a152dd715b642afd5ec0a7b2ee1c6b3
|
File details
Details for the file mpl3d_turbo-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
384da56da356165ec600306df6d967e4c98cb3be07113037442ba7aba7506545
|
|
| MD5 |
58ce108e20b574f6b3ec19b8f407b1dd
|
|
| BLAKE2b-256 |
7d04cd115671f6dcf1b32738711903bb3b6bd462edf422fb67cb1ca0c978a5af
|
File details
Details for the file mpl3d_turbo-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 217.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e89f9eb043c2409edd98090172dbf80e0446f99e89f4170479c47cd532cefde
|
|
| MD5 |
d8a536686552e3376397a6fe049c4e4e
|
|
| BLAKE2b-256 |
d3e48c5068ea54b2220db1f3af1d3f6e074a273f726699cea2726b722e2988bc
|
File details
Details for the file mpl3d_turbo-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d475a7464e8b92821f10b0fbea3ceeab3e79951d0a6b2b5c05a8924f40e29fd8
|
|
| MD5 |
dda102dbf1b23581b7d0e53c67d9a7ea
|
|
| BLAKE2b-256 |
f56ea5c54973f4cfc1dd281c5f9a201c63928e997d2fc57f25c62558017546f6
|
File details
Details for the file mpl3d_turbo-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 217.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b83148f26c32f6f8d347a9e12a660433898c20138dc4000b29a14a9541707ef2
|
|
| MD5 |
e83ac7e800fa3d2bc3c771c32faa37a5
|
|
| BLAKE2b-256 |
579108e23e45b3c5a3a51b92fd822eb6f20519bd611be3b14479db82de6feea5
|
File details
Details for the file mpl3d_turbo-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aa5567fd61724027bfa8054a47e79fdafa963f1e78fd15e70df75a8c4a82ef9
|
|
| MD5 |
1ec46ee886c0003e092365d11c9b8667
|
|
| BLAKE2b-256 |
714d80219c0867ab73ef856d4c9b5544d7532f28755e93d5882ffd0ac6eaffeb
|
File details
Details for the file mpl3d_turbo-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 217.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be499544eca0e07712b1b41bccb5a1936c2b5e4d62e44e5f81c364a52c0506f3
|
|
| MD5 |
f2a217feadacacf3d87cc904a67ceabf
|
|
| BLAKE2b-256 |
f6e2fe9447abf194f6b34160ad8b9ad9c383fc7ecf4f4362a43a4f89cf0d0a05
|
File details
Details for the file mpl3d_turbo-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.5 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3825e8f2fa612f9234fa99d277579ecb1adb5c955a64f04068be36c95bd9d7d5
|
|
| MD5 |
dbfc6e8caaf98be2eff485f5e8286371
|
|
| BLAKE2b-256 |
6fbb79b7e2250c8f8720cb9aa035b572a52e03c125190ad68c3d7facc1eddb30
|
File details
Details for the file mpl3d_turbo-0.1.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 218.0 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b39f3728814e1d57889f4b072185e26a774bbb87463d6f387587444519d973c9
|
|
| MD5 |
ec2d018c1d21724c2a00672d72a0b093
|
|
| BLAKE2b-256 |
3bec32c82f185503a6d23539dc21362e85858bf84957d1454be28674efb793f6
|
File details
Details for the file mpl3d_turbo-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 341.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9994c9012bfd4f86c5316d6abefe50bd0f91b315bda53ef8128affde87919ea9
|
|
| MD5 |
95edea8ae9f916289c6f61364a3579fa
|
|
| BLAKE2b-256 |
f675390ec9e02f9a0fc82136723a1bc65adc8f732be33f4a4d06f52f050869fd
|
File details
Details for the file mpl3d_turbo-0.1.0-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 218.2 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d299118b12d6ac0851136acf7a123c09ee53f5741c585f573b241548fdc364
|
|
| MD5 |
1d4b74459bd637099077b9bf16cf53e0
|
|
| BLAKE2b-256 |
2263c6ad96d3507f98c602d9516a542822acef3bf49f41c5de21cdcde0973820
|
File details
Details for the file mpl3d_turbo-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mpl3d_turbo-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 342.2 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de7654b982276479c3d69627dddc4eed8d0207424d07a7553d1abf63823b0f36
|
|
| MD5 |
6557a1fbc431a1e51657f13921f63e1f
|
|
| BLAKE2b-256 |
869899092a4a41f5c5b42006d6efafda542519237c6da8ed04d7a69cd06f1435
|