aquarel: Lightweight templating engine for matplotlib

0.0.7 · active · verified Sun Apr 12

Aquarel is a lightweight templating engine and wrapper around Matplotlib's rcparams designed to simplify plot styling. It enables programmatic definition and JSON serialization of themes, facilitating sharing and consistent visualization across projects. Beyond standard Matplotlib stylesheets, Aquarel introduces 'transforms' for aesthetics not achievable via rcparams alone, such as trimmed axes. The library is actively maintained with frequent minor updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to apply an Aquarel theme using a context manager. The `load_theme()` function fetches a predefined theme, which is then applied within the `with` block. All plotting commands inside this block will adopt the specified theme. Remember that `plt.savefig()` or `plt.show()` should be called *outside* the context manager if transforms are used, to ensure they are correctly applied.

import matplotlib.pyplot as plt
import numpy as np
from aquarel import load_theme

# Define a sample plotting function
def create_plot():
    fig, ax = plt.subplots(figsize=(8, 6))
    x = np.linspace(0, 10, 100)
    y = np.sin(x)
    ax.plot(x, y, label='Sine Wave')
    ax.set_title('Sample Plot')
    ax.set_xlabel('X-axis')
    ax.set_ylabel('Y-axis')
    ax.legend()
    return fig

# Apply a theme using a context manager
with load_theme('arctic_light'):
    fig = create_plot()
    plt.savefig('arctic_light_plot.png')
    # In a non-script environment (e.g., Jupyter), you might call plt.show() here if needed

print('Plot with arctic_light theme saved to arctic_light_plot.png')

view raw JSON →