Small utility for creating reproducible figures.
Project description
Reproducible Figures
A small Python utility to generate easily reproducible figures for scientific papers. I often find myself generating figures for papers and then having to go through needlessly tedious processes to regenerate them when I want to make a small change, so I made this package. By generating figures using this package a folder is created with the figure, the data used to generate the figure, and the code used to generate the figure. I recommend combining this with a version control system like git to track changes for your figures.
Installation
pip install reproducible_figures
Example Usage
from reproducible_figures import save_reproducible_figure
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def create_figure(data):
fig, ax = plt.subplots()
ax.plot(data['x'], data['y'])
return fig
data = pd.DataFrame({
'x': range(10),
'y': np.random.normal(size=10)
})
save_reproducible_figure('test_save_figure', data, create_figure)
This will create the folder figures/test_save_figure with the following structure:
figures/test_save_figure
├── data.csv
├── test_save_figure.pdf
└── code.py
The data.csv file contains the data used to generate the figure, the figure.pdf file contains the figure itself, and the code.py file contains the code used to generate the figure.
In order to reproduce the figure, you can run:
python figures/test_save_figure/code.py
If you want to modify the figure, you can edit the code.py file and run it again.
Advanced Usage
Additional Imports
By default, the only libraries available in the code.py file are pandas as pd and matplotlib.pyplot as plt, matplotlib, numpy as np, and seaborn as sns. If you want to use other libraries, you can pass them to the save_reproducible_figure function:
save_reproducible_figure('test_save_figure',
data,
create_figure,
additional_imports=['import networkx as nx'])
This will add import networkx as nx to the code.py file.
See the tests for an example using networkx to generate a figure.
Helper Functions
If you want to use helper functions in your code.py file, you can pass them to the save_reproducible_figure function. For example:
def preprocess_data(data: pd.DataFrame) -> pd.DataFrame:
"""Preprocess data."""
data['y'] = data['y'] * 100
return data
def create_test_figure_with_helper_fns(data: pd.DataFrame):
"""Create a figure."""
fig, ax = plt.subplots()
data = preprocess_data(data)
ax.plot(data['x'], data['y'])
save_reproducible_figure('test_fig_preprocessor', data,
create_test_figure_with_helper_fns,
helper_fns=[preprocess_data])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reproducible_figures-1.0.0.tar.gz.
File metadata
- Download URL: reproducible_figures-1.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e86a93488c526b02cf8221bfec1c2ae10d409270dbe76ea6df0acadcbbdf9c
|
|
| MD5 |
0de3e6491cfcfab818e165229d4fd40e
|
|
| BLAKE2b-256 |
01a053df8b7734ab6c02f117929b8393a8b055bb566c210e1d9545e67bae7c94
|
File details
Details for the file reproducible_figures-1.0.0-py3-none-any.whl.
File metadata
- Download URL: reproducible_figures-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5be463b1e319b692a765e580764a359bcce0814ea2bb24d9a1887c9f059e5f8a
|
|
| MD5 |
f5a4ae35b857868137dbc5881c68a3cb
|
|
| BLAKE2b-256 |
79ea86a69628d9f94e22e8bb2257ceb65209b2d676e8b306b6705544a86ab6b7
|