Skip to main content

A flexible subplot layout library for matplotlib with support for adding panels in all directions

Project description

Sunmao

PyPI version Documentation Status Python Support License: MIT

A flexible subplot layout library for matplotlib with support for adding panels in all directions using the traditional Chinese mortise-tenon joinery concept.

Features

  • 🎯 Mortise-Tenon Architecture: Traditional Chinese joinery concept for flexible layouts
  • 📐 Four-Directional Expansion: Add panels in all directions (top, bottom, left, right)
  • 🎨 Independent Axes: Each panel is a fully customizable matplotlib axes object
  • 🌳 Nested Structures: Support for complex nested panel hierarchies
  • 📊 Unified Legend Management: Automatic legend positioning and management
  • ⚡ Auto Alignment: Automatic axis alignment between adjacent panels
  • 🔧 Full Matplotlib Integration: Direct access to all matplotlib plotting functions

Installation

pip install sunmao

Or using Poetry:

poetry add sunmao

Quick Start

import numpy as np
import matplotlib.pyplot as plt
from sunmao import mortise

# Create the root mortise
fig, root = mortise(width=2, height=2, figsize=(10, 8))

# Add tenons in different directions
top_panel = root.tenon(pos='top', size=1, title='Top Panel')
bottom_panel = root.tenon(pos='bottom', size=1, title='Bottom Panel')
left_panel = root.tenon(pos='left', size=1, title='Left Panel')
right_panel = root.tenon(pos='right', size=1, title='Right Panel')

# Plot data
x = np.linspace(0, 10, 100)
root.plot(x, np.sin(x), 'b-', linewidth=2, label='sin(x)')
top_panel.plot(x, np.cos(x), 'r-', linewidth=2, label='cos(x)')
bottom_panel.plot(x, np.sin(x)**2, 'g-', linewidth=2, label='sin²(x)')
left_panel.plot(x, np.exp(-x/5), 'orange', linewidth=2, label='exp(-x/5)')
right_panel.scatter(x[::5], np.cos(x[::5]), c=x[::5], cmap='viridis', s=20)

# Create unified legend
root.create_legend(mode='auto')

plt.show()

Advanced Features

Legend Management

Sunmao provides unified legend management with four modes:

# Global legend for all panels
root.create_legend(mode='global', position='upper center', ncol=2)

# Individual legend for each panel
root.create_legend(mode='local')

# Mixed mode (global + local)
root.create_legend(mode='mixed', position='upper center')

# Automatic mode selection
root.create_legend(mode='auto')

Axis Alignment

Automatic axis alignment between adjacent panels:

# Automatic alignment when adding tenons
top_panel = root.tenon(pos='top', size=1, auto_align=True)

# Manual alignment
root.align_axes('x')  # Align x-axis
root.align_axes('y')  # Align y-axis
root.align_axes('both')  # Align both axes

Nested Structures

Support for unlimited nesting:

# Create nested structure
fig, root = mortise(width=2, height=2)

# First level
top_panel = root.tenon(pos='top', size=1)

# Second level
top_left = top_panel.tenon(pos='left', size=1)

# Third level
top_left_top = top_left.tenon(pos='top', size=0.5)

Documentation

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/seqyuan/sunmao.git
cd sunmao

# Install in development mode
poetry install

# Run tests
make test

# Run linting
make lint

Release Process

See RELEASE_GUIDE.md for detailed instructions on:

  • 🚀 Pushing to GitHub
  • 📦 Publishing to PyPI
  • 📚 Setting up ReadTheDocs documentation
  • 🔄 Automated CI/CD with GitHub Actions

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sunmao-0.3.3.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sunmao-0.3.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file sunmao-0.3.3.tar.gz.

File metadata

  • Download URL: sunmao-0.3.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sunmao-0.3.3.tar.gz
Algorithm Hash digest
SHA256 86738f0f2b75db96c56977482d5ffe5c55748267e295c5bc2070a583fc5968a1
MD5 304f61aca75658df934f1fd319a2bb70
BLAKE2b-256 f34f9c19d18e85f92b51bc70bb4c67f3912d03761d2e94d8ee3d6728b873920d

See more details on using hashes here.

File details

Details for the file sunmao-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: sunmao-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sunmao-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c3288cf1d5c22f29561345f79fcaf1719ed7f78a482871f2e6495449cef4b722
MD5 6dd0ee4357cf72a3c1c7ba370a64ad49
BLAKE2b-256 2c2033ef6415717562e74233cd39fefc59bdd2c0ff7a42cf341cf4b7c7777065

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page