🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

mpl3d-turbo

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpl3d-turbo

High-performance Matplotlib 3D plotting library implemented in Rust

0.1.0
PyPI
Maintainers
1

mpl3d-turbo: Accelerated 3D Rendering for Matplotlib

License: MIT Python 3.7+ Matplotlib 3.5+

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
# 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 SizeStandard Matplotlibmpl3d-turboSpeedup
100x1000.032s0.030s1.09x
200x2000.049s0.036s1.37x
500x5000.115s0.080s1.44x
1000x10000.354s0.217s1.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.

Keywords

matplotlib

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts