Can matplotlib add metadata to saved figures?

后端 未结 4 905
青春惊慌失措
青春惊慌失措 2021-01-31 16:53

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

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 17:10

    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")
    

提交回复
热议问题