econ-ark/HARK

utilities.py: metadata bug in make_figs()

Closed this issue · 7 comments

When calling make_figs(), an unrecognized argument error occurs at:

plt.savefig(
            os.path.join(target_dir, f"{figure_name}.jpg"),
            metadata={"CreationDate": None},
) 

The matplotlib.pyplot.savefig documentation says metadata is currently not supported for .jpeg files. Commenting out the metadata argument stops the error and the figure is produced as expected.

Should metadata={"CreationDate": None} be removed from the JPEG savefig call until support is added in a later version of the package?

It might be better to use .gitignore to suppress version control over the jpegs entirely.

Matt,

As the original author of savefig, can you look into this? I'm puzzled that a lot more examples have not cropped up.

Also, my preference would be that whenever a figure is saved, it gets saved in jpg, pdf, svg, and png forms.

Well, I don't remember writing it either but as you say it was in a galaxy far far away so maybe I did.

I do remember adding some code to suppress metadata, but I think that that was in a version that saved all four kinds of figures automatically (jpg, svg, pdf, png) and I worked out how to suppress the metadata for all of them (because there would be no point in suppressing it for just one).

In any case, I'm puzzled that the problem has not cropped up for any of our REMARKs or other tests, so maybe none of them uses savefig. Actually, @edmundcrawley, can you point Matt to the place in the HAFiscal-Latest code where the savefig command is invoked, so he can see the content (I've just invited him as a collaborator on HAFiscal-Latest; please let Matt know the name of the branch you've been testing against HARK 0.13 on.)

@mnwhite here is a minimal working example that shows the problem - that is probably easier than pointing you to the code in HAFiscal-Latest. Let me know if this doesn't work for you.

from HARK.utilities import make_figs
import matplotlib.pyplot as plt
import numpy as np

plt.figure()
plt.plot(np.linspace(1,5,40),np.linspace(4,8,40) )
make_figs('test', True , False, target_dir="C:/Downloads")
plt.show()

I get the error:

TypeError: print_jpg() got an unexpected keyword argument 'metadata'

Thanks @edmundcrawley , that was a perfect example. I've made a PR that fixes this in #1386 and will merge ASAP, then try to do a minor release.