Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utilities.py: metadata bug in make_figs() #1375

Closed
kennetheva opened this issue Jan 29, 2024 · 7 comments · Fixed by #1386
Closed

utilities.py: metadata bug in make_figs() #1375

kennetheva opened this issue Jan 29, 2024 · 7 comments · Fixed by #1386
Assignees

Comments

@kennetheva
Copy link

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?

@llorracc
Copy link
Collaborator

llorracc commented Jan 30, 2024 via email

@sbenthall
Copy link
Contributor

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

@llorracc
Copy link
Collaborator

llorracc commented Feb 2, 2024

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.

@mnwhite
Copy link
Contributor

mnwhite commented Feb 2, 2024 via email

@llorracc
Copy link
Collaborator

llorracc commented Feb 2, 2024

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

@edmundcrawley
Copy link
Contributor

@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'

@mnwhite
Copy link
Contributor

mnwhite commented Feb 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants