Skip to main content

How did I create that plot again 🤔

Project description

Re-plot

a.k.a. How did I create that plot again 🤔


Python matplotlib git

Did you ever want to recreate an old plot, changing just a small bit, but didn't manage because ...

  • ... wait, which script did I use to create that plot?
  • ... wait, what arguments did I pass to that script?
  • ... wait, what version of all involved libraries did I use?
  • ... wait, what environment variables were set at that time?
  • ... wait, what is the correct version of the data files?
  • ... wait, where did all the data files go?
  • ...

This project aims to solve (most of) these problems and make plots fully reproducible at any time later in history.

Concept

The approach relies on two aspects, metadata and capturing.

  • Metadata is all the information that's addressed by the above questions, such as library versions, command line arguments, environment variables, etc.
  • Capturing describes the way in which the metadata is stored together with the image.

The current version of replot saves the following metadata as the UserComment Exif tag together with the image (as a JSON dictionary):

  • the current working directory
  • script file path relative to repository root
  • command line arguments
  • environment variables
  • version of all packages in the current virtual environment
  • a snapshot of matplotlib.rcParams
  • current commit hash

How does it work?

All you need to do is import replot somewhere at the top of your script and then save your figures via the matplotlib Figure.savefig method. Behind the scenes, replot patches this method in order to add the metadata information.

File dependencies

replot monitors dependencies on external files by intercepting the following function calls:

Data that is accessed in different ways won't be added to the list of dependencies. Custom data loaders can be registered for monitoring via replot.monitor.

In addition, it counts the main script as well as any other imported custom modules as file dependencies.

If any of the file dependencies is not part of the git repository or if it contains unsaved changes, replot will refuse to create a new image via Figure.savefig. Instead it will print a warning which informs about the unsaved file dependencies. This warning can be suppressed via from replot import nowarn. A typical workflow would be to repeatedly view the plot via plt.show(), then commit all the changes and then running the script again will also create the plot image.

How to view the data?

The replot package can be used to print the metadata in JSON format by passing the image file path as a command line argument or by passing the User Comment field of the Exif data via stdin; for example:

python -m replot test.png
exiftool -UserComment test.png | python -m replot

This will print all metadata information, however typically the commit_hash field is sufficient, given that replot enforces putting all file dependencies under version control before a figure can be saved.

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

replot-0.1.4.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

replot-0.1.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: replot-0.1.4.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for replot-0.1.4.tar.gz
Algorithm Hash digest
SHA256 31bf2590d9634c2bc3340f968f14a431f55ea262c64ebc028dd5f4816afdcf0c
MD5 abb4fd8ca273a69749995552d9992e21
BLAKE2b-256 6a3a6894f9993d5bc118d040d2a2f02b57fd900d7738c6df0e2800bd9507874d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: replot-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for replot-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7c21aaca3c78213a8faf44469c3617619f2b8cc1260f8748f9d7408e96d8022c
MD5 b6e4cdcd2c881a6a9d03cded5368dd12
BLAKE2b-256 9e8ed88611e3b4dd987a3d8ac5e7674fca5412d624d628e52826b599bfd2e268

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page