Skip to main content

driedfigs

Preserve your matplotlib figures with their data for reproducible research.

driedfigs makes it simple to save the data behind your matplotlib plots alongside your figures, improving reproducibility in academic publications.

Key Features

  • Zero effort reproducibility: Automatically capture plot data with minimal code changes
  • Non-intrusive: Works with existing matplotlib code - just add name parameters
  • Flexible: Supports most matplotlib plotting functions (plot, scatter, contour, etc.)
  • Simple API: Just two main functions - start_figure() and save_figuredata()

Installation

pip install driedfigs

For xarray support (automatic conversion of DataArrays to numpy):

pip install driedfigs[xarray]

Quick Start

import driedfigs as df
import matplotlib.pyplot as plt
import numpy as np

# 1. Start capturing data for a figure
fig_data = df.start_figure("example_plot")

# 2. Create plots with the 'name' parameter to identify each artist
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x), name="sin_wave")
plt.scatter([1, 2, 3], [0.5, 0.8, 1.2], name="data_points")

# 3. Save the data
df.save_figuredata("./data/example_plot.pkl")

# 4. Save the figure (as you would normally)
plt.savefig("./figures/example_plot.pdf")

This creates:

  • ./figures/example_plot.pdf (the figure, saved normally)
  • ./data/example_plot.pkl (the captured data)

The way driedfigs works is simple:

  • When driedfigs is imported, it overwrites commonly used matplotlib plotting functions and methods with "hooked" versions of the function/method that first store the data before calling the function/method normally
  • When you call start_figure, a FigureData object for storing that figure's data is created
  • When you call any of the "hooked" functions/methods with a name keyword argument, the data is stored in the current FigureData object
  • When you call save_figuredata, all of the data in the FigureData object is saved to disk using python's pickle module

Detailed Usage

Basic Workflow

import driedfigs as df
import matplotlib.pyplot as plt

# Start a new figure
fig_data = df.start_figure("my_analysis", verbose=True)

# Make plots - use 'name' to capture data
plt.plot(x_data, y_data, name="raw_data")
plt.plot(x_model, y_model, '--', name="model_fit")

# Save the data
df.save_figuredata("./data/my_analysis.pkl")

# Save the figure (standard matplotlib)
plt.savefig("./figures/my_analysis.pdf")
plt.savefig("./figures/my_analysis.png", dpi=300)

Loading Saved Data

import pickle

# Load the saved data
with open("data/my_analysis.pkl", "rb") as f:
    data = pickle.load(f)

# Access specific plot data
raw_data = data["raw_data"]  # Returns tuple of args passed to plt.plot
x, y = raw_data[0], raw_data[1]

Supported Matplotlib Functions

pyplot functions:

plot, scatter, bar, hist, imshow, contour, contourf, pcolormesh, fill_between, errorbar, boxplot, violin, pie, polar, loglog, semilogx, semilogy

Axes methods:

plot, scatter, bar, hist, imshow, contour, contourf, pcolormesh, fill_between, errorbar, boxplot, violin

Managing Multiple Figures

# Create separate figure data objects
fig1 = df.start_figure("figure_1")
plt.plot(x1, y1, name="data1")
fig1.save("./data/figure1.pkl")  # Use the .save() method

fig2 = df.start_figure("figure_2")
plt.plot(x2, y2, name="data2")
fig2.save("./data/figure2.pkl")

Real-World Example

import driedfigs as df
import matplotlib.pyplot as plt
import numpy as np

# Simulate some research data
time = np.linspace(0, 10, 100)
measurement = np.sin(time) + np.random.normal(0, 0.1, 100)
model = np.sin(time)

# Start capturing
df.start_figure("experiment_results")

# Create publication-quality plot
plt.figure(figsize=(10, 6))
plt.plot(time, measurement, 'o', alpha=0.5, label="Measurements", name="raw_measurements")
plt.plot(time, model, '-', linewidth=2, label="Model", name="theoretical_model")
plt.xlabel("Time (s)")
plt.ylabel("Signal (V)")
plt.legend()
plt.title("Experimental Results vs. Theoretical Model")

# Save the data for reproducibility
df.save_figuredata("./manuscript/data/experiment_results.pkl")

# Save the figure
plt.savefig("./manuscript/figures/experiment_results.pdf")
plt.savefig("./manuscript/figures/experiment_results.png", dpi=300)

# Now you can upload ./manuscript/ with your paper submission!

API Reference

Main Functions

  • start_figure(name, verbose=False): Begin capturing data for a new figure

    • Returns a FigureData instance
    • Automatically installs hooks on first use
  • save_figuredata(output_path, figuredata=None): Save captured data to a pickle file

    • If figuredata is None, uses the currently active FigureData

FigureData Class

  • save(output_path): Save this figure's data to file
  • figure_name: Name of the figure
  • figure_data: Dictionary mapping artist names to their data
  • is_active: Whether this FigureData is currently active

Metadata

Release files for driedfigs 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for driedfigs 0.1.0
File Size Uploaded Provenance
driedfigs-0.1.0.tar.gz 32.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for driedfigs 0.1.0
File Interpreter ABI Platform
driedfigs-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.1 kB

Release files / driedfigs-0.1.0.tar.gz

Download URL driedfigs-0.1.0.tar.gz
Size 32.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7a3ad3ba3df83e9dd094be362bd297aa500296bf0b793f274d630c4ad7f1d0f8
BLAKE2b-256 checksum
How to use checksums
54e272acb1853f2365ae76d945f54a8fb2cfac608c4acfc5e35172b9d666f997
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / driedfigs-0.1.0-py3-none-any.whl

Download URL driedfigs-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a7a75478e066610a83554eee30fc9de14733064fe3b514b67a4ec003bb7e1a6
BLAKE2b-256 checksum
How to use checksums
d0fb07ead1c4cc21c503a4e325fef0c5a15c5ac1a564d3c451a0c745aa66d655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for driedfigs 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page