Skip to main content

A Jupyter magic command for creating reproducible matplotlib figures.

Project description

lusca

Python PyPI - Version CI Ruff

pip install lusca

lusca is a Python library for creating reproducible matplotlib figures using Jupyter magic commands. You often want to use Jupyter for experiments without rerunning the entire notebook to recreate a plot, and saving data alongside figures is essential for artifact generation and reproducibility.


%%mplfreeze

%%mplfreeze <name> [vars ...] [--outdir DIR]
  • <name>: Base name for outputs (folder + files).
  • [vars ...]: Variable names to save into the NPZ file.
  • [--outdir DIR]: Parent output directory (default: docs/figs).

The magic command:

  • Captures the data used in your plots and saves it in a compressed NPZ file.
  • Exports your figures in PDF, PNG, and SVG.
  • Generates a minimal standalone script that reproduces the figure.
  • Snapshots Python/package versions and the git commit into <name>.meta.json.
  • Statically checks the cell for unsaved free names before writing anything, then runs the generated replot in a subprocess to confirm the bundle actually reproduces the figure - if %%mplfreeze succeeds, the replot is guaranteed to work.
  • Applies lusca's built-in stylesheet.

Example

import matplotlib.pyplot as plt
import numpy as np
import lusca
%load_ext lusca
x_data = np.linspace(-10, 10, 100)
sine = np.sin(x_data)
cosine = np.cos(x_data)
%%mplfreeze trig_demo x_data sine cosine
with plt.style.context("lusca"):
    fig, ax = plt.subplots(1, 1, figsize=(3.5, 2.6), sharey=True)
    ax.plot(x_data, sine, label="Sine")
    ax.plot(x_data, cosine, label="Cosine")
    plt.show()

An example notebook is available in src/demo.ipynb. Generated plots are saved under docs/figs/:

name_stamp/
    name.npz             # saved variables
    name.pdf             # exported figure
    name.png
    name.svg
    name.meta.json       # python/package versions + git commit
    replot_name.py       # standalone replot script

[!NOTE] If you are using VS Code, set the workspace root as the default directory for saving figures by adding the following to your settings.json. Otherwise, output paths will be relative to the notebook location.

"jupyter.notebookFileRoot": "${workspaceFolder}"

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

lusca-0.1.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

lusca-0.1.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file lusca-0.1.2.tar.gz.

File metadata

  • Download URL: lusca-0.1.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lusca-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5a8b0cef8abcfa955d1bf51004545b87a3395b5c8f0af0993e69c9c3ca639975
MD5 83a10ac3ddd3854eb496f2812f6024e4
BLAKE2b-256 25214b43ea91f47bf6b505c329e54ba66a593d4b287351455ba82820567238aa

See more details on using hashes here.

File details

Details for the file lusca-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lusca-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lusca-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4fc002186a7e556c7e7882bd757a98386c60e2945a97e596f8159f79cadfd6b2
MD5 6ae743458739ac2f12e407114f676a96
BLAKE2b-256 2101e941a62b2d8a7d88f6ff99925ee7247072958ca026d8ad95f6d2ac0bf163

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