I want to be able to ascertain the provenance of the figures I create using matplotlib, i.e. to know which version of my code and data created these figures. (See this essay for
If you are generating SVG files, you can simply append text as an XML comment at the end of the SVG file. Editors like Inkscape appear to preserve this text, even if you subsequently edit an image.
Here's an example, based on the answer from Hooked:
import pylab as plt
import numpy as np
f = "figure.svg"
X = np.random.random((50,50))
plt.imshow(X)
plt.savefig(f)
open(f, 'a').write("\n")