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.3.tar.gz (14.2 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.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lusca-0.1.3.tar.gz
  • Upload date:
  • Size: 14.2 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.3.tar.gz
Algorithm Hash digest
SHA256 2f48fbd65e8b539f13111e9d2c1a7b99fd11aadcd3e0135d97c5b68db7ab6e44
MD5 298ea7fe243b0d744d68628e97f99046
BLAKE2b-256 6d18616aed32364a9f36284c11a9c183bda692f49ed47555d0c53c5c195d0c4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lusca-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba48113adad89902f94865d91e14129c23689b2bdb3e8985cce35a6d98157a2d
MD5 b0c73adcb3b3b65186d660037541ded4
BLAKE2b-256 2a89c07e00d45f3e9ea73241db02a74d97a3f0d45aacc869ce28c78cfee30874

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