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.4.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.4-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lusca-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 0e6cdb78a310b5bbec1ca98a1ddb6a2e33b8de9575148105dc63818f5703183f
MD5 63db155786c88a5c9757f49e1553d456
BLAKE2b-256 20d9f0f9ff19071cf0e0f453427eec01b35a24eca415ad538be7167008c4c793

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lusca-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 19fe2c0fe197db035be83f9db890bc0a9846d3e65faffe400aa5db7954542afe
MD5 969fa9ea6a0aaab683a50a6d6416db00
BLAKE2b-256 9a0f1afa8d85c7cbf74ff4866c4208dd8696db7a3bfac217a16880767a499b17

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