Skip to main content

Matplotlib style sheets based on seaborn-v0_8-dark theme with combinable palettes and contexts

Project description

mplstyles-seaborn

Python License Matplotlib Tests codecov GitHub last commit GitHub issues Type hints Styles

Matplotlib style sheets based on seaborn v0.8 themes with combinable palettes and contexts.

Overview

While matplotlib includes built-in seaborn v0.8 style sheets, they offer only a limited set of predefined combinations. This package extends matplotlib's seaborn styling without requiring seaborn as a dependency, providing all 120 possible combinations of seaborn's styles, color palettes, and contexts.

Features

  • Zero seaborn dependency: Use seaborn-style plots with pure matplotlib
  • Complete coverage: All 120 combinations of seaborn v0.8 styles, palettes, and contexts
  • Easy integration: Styles automatically registered with matplotlib on import
  • Multiple usage methods: Convenience functions or direct matplotlib integration
  • Type hints: Full type annotation support

Comprehensive Plot Demonstration

Example Galleries

For comprehensive visual examples, see our 📸 Example Galleries:

Installation

Install from PyPI:

pip install mplstyles-seaborn

Or with uv:

uv add mplstyles-seaborn

Development Installation

For development, install directly from GitHub:

pip install git+https://github.com/monodera/mplstyles-seaborn.git

Or with uv:

uv add git+https://github.com/monodera/mplstyles-seaborn.git

Quick Start

import matplotlib.pyplot as plt
import mplstyles_seaborn
import numpy as np

# Generate sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)

# Method 1: Use convenience function
mplstyles_seaborn.use_style('whitegrid', 'colorblind', 'talk')

plt.figure(figsize=(10, 6))
plt.plot(x, y, label='sin(x)')
plt.title('Example Plot')
plt.legend()
plt.show()

Available Options

Styles (5 options)

  • darkgrid - Dark grid background
  • whitegrid - White grid background
  • dark - Dark background, no grid
  • white - White background, no grid
  • ticks - White background with ticks

Palettes (6 options)

  • dark - Deep, saturated colors
  • colorblind - Colorblind-friendly palette
  • muted - Muted, subdued colors
  • bright - Bright, vibrant colors
  • pastel - Light, pastel colors
  • deep - Dark, deep colors

Contexts (4 options)

  • paper - Smallest elements, for papers/publications
  • notebook - Default size, for notebooks
  • talk - Larger elements, for presentations
  • poster - Largest elements, for posters

Usage Methods

1. Convenience Function

import mplstyles_seaborn

# Use all three parameters
mplstyles_seaborn.use_style('whitegrid', 'colorblind', 'talk')

# Use defaults for some parameters (defaults: darkgrid, dark, notebook)
mplstyles_seaborn.use_style(palette='colorblind', context='talk')

2. Direct Matplotlib

import matplotlib.pyplot as plt

# Styles are automatically registered on import
plt.style.use('seaborn-v0_8-whitegrid-colorblind-talk')

3. List Available Styles

import mplstyles_seaborn

# See all 120 available style combinations
styles = mplstyles_seaborn.list_available_styles()
print(f"Available styles: {len(styles)}")

# Print first few styles
for style in styles[:5]:
    print(style)

Run the examples with:

# Basic usage examples
uv run python examples/basic_usage.py

# Generate all 120 style combination comparisons  
uv run python examples/style_comparison.py

# Comprehensive demonstration with 7 different plot types
uv run python examples/comprehensive_demo.py

Basic Line Plot

import matplotlib.pyplot as plt
import numpy as np
import mplstyles_seaborn

# Apply style
mplstyles_seaborn.use_style('whitegrid', 'colorblind', 'talk')

# Create plot
x = np.linspace(0, 10, 100)
fig, ax = plt.subplots(figsize=(10, 6))

ax.plot(x, np.sin(x), label='sin(x)', linewidth=2)
ax.plot(x, np.cos(x), label='cos(x)', linewidth=2)
ax.plot(x, np.sin(x + np.pi/4), label='sin(x + pi/4)', linewidth=2)

ax.set_title('Trigonometric Functions')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.legend()

plt.tight_layout()
plt.show()

Scatter Plot

import matplotlib.pyplot as plt
import numpy as np
import mplstyles_seaborn

# Apply dark theme with muted palette
mplstyles_seaborn.use_style('dark', 'muted', 'notebook')

# Generate data
np.random.seed(42)
x = np.random.randn(200)
y = np.random.randn(200)

# Create scatter plot
fig, ax = plt.subplots(figsize=(8, 6))
ax.scatter(x, y, alpha=0.7, s=60)
ax.set_title('Random Scatter Plot')
ax.set_xlabel('X values')
ax.set_ylabel('Y values')

plt.tight_layout()
plt.show()

Font Configuration

The package includes optimized font settings:

  1. Source Sans 3 (if available)
  2. Arial (fallback)
  3. DejaVu Sans (further fallback)
  4. System fonts

Font family is automatically set to sans-serif for consistent appearance.

API Reference

Functions

use_style(style='darkgrid', palette='dark', context='notebook')

Apply a seaborn-v0.8 style with specified parameters.

Parameters:

  • style (str): Style type - 'darkgrid', 'whitegrid', 'dark', 'white', 'ticks'
  • palette (str): Color palette - 'dark', 'colorblind', 'muted', 'bright', 'pastel', 'deep'
  • context (str): Context scaling - 'paper', 'notebook', 'talk', 'poster'

list_available_styles()

Returns a sorted list of all 120 available style names.

Returns:

  • list[str]: List of style names

register_styles()

Register all styles with matplotlib (called automatically on import).

Constants

  • STYLES: List of available style types
  • PALETTES: List of available color palettes
  • CONTEXTS: List of available contexts

Development

Requirements

  • Python >=3.11
  • matplotlib >=3.5
  • seaborn >=0.11 (for development/generation only)

Setup

git clone https://github.com/monodera/mplstyles-seaborn.git
cd mplstyles-seaborn
uv sync

Testing

This project includes comprehensive tests covering:

  • Unit tests for all API functions
  • Integration tests with matplotlib
  • Validation tests for all 120 style files
  • Error handling and edge cases
  • Performance benchmarks

Running Tests

# Install test dependencies
uv sync --extra test

# Run all tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=src/mplstyles_seaborn --cov-report=term-missing

# Run specific test categories
uv run pytest tests/test_api.py          # API function tests
uv run pytest tests/test_integration.py # Matplotlib integration tests
uv run pytest tests/test_styles.py      # Style file validation tests
uv run pytest tests/test_errors.py      # Error handling tests

# Run performance tests (marked as slow)
uv run pytest tests/test_performance.py -m "not slow"  # Fast performance tests
uv run pytest tests/test_performance.py                # All performance tests

# Run with verbose output
uv run pytest -v

Manual Testing

# Test package import and basic functionality
uv run python -c "import mplstyles_seaborn; print(len(mplstyles_seaborn.list_available_styles()))"

# Test specific style application
uv run python -c "import matplotlib.pyplot as plt; plt.style.use('seaborn-v0_8-whitegrid-colorblind-talk')"

# Run example scripts
uv run python examples/basic_usage.py
uv run python examples/style_comparison.py
uv run python examples/comprehensive_demo.py

Regenerating Styles

# Generate and fix all 120 style files in one command (recommended)
uv run python scripts/build_styles.py

# Alternative: Generate only (for development/testing)
uv run python scripts/build_styles.py --generate-only

# Alternative: Fix existing files only
uv run python scripts/build_styles.py --fix-only

License

This project is licensed under the MIT License.

Contributing

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

Development Support

This project was primarily developed using Claude Code, Anthropic's AI-powered coding assistant.

Related Projects

  • seaborn - Statistical data visualization library
  • matplotlib - Python plotting library

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

mplstyles_seaborn-0.2.5.tar.gz (17.5 MB view details)

Uploaded Source

Built Distribution

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

mplstyles_seaborn-0.2.5-py3-none-any.whl (104.0 kB view details)

Uploaded Python 3

File details

Details for the file mplstyles_seaborn-0.2.5.tar.gz.

File metadata

  • Download URL: mplstyles_seaborn-0.2.5.tar.gz
  • Upload date:
  • Size: 17.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mplstyles_seaborn-0.2.5.tar.gz
Algorithm Hash digest
SHA256 448b2df0986970763d44cb8900f50431dc4b5686edfd7dabadd59eb4b2b908e5
MD5 4f2361d383c4772ba004339b7ca91021
BLAKE2b-256 ed6b278de3eff092eb7c2575f8aea5c3c3a8c5ec8c0a19ca0be45954e2cc65e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mplstyles_seaborn-0.2.5.tar.gz:

Publisher: python-publish.yml on monodera/mplstyles-seaborn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mplstyles_seaborn-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mplstyles_seaborn-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aabe7b99d5272c3be78de92f62fbf8a839844e37ecfe25ac895e23de1f1eb715
MD5 3b51ea627b44d93a6b7fca6228fc70fb
BLAKE2b-256 cfa002e35b29c5ded94644f57393f7f87ecf9c8a9f29b6362ec37a79550247d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mplstyles_seaborn-0.2.5-py3-none-any.whl:

Publisher: python-publish.yml on monodera/mplstyles-seaborn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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