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

Regression from 8.2: AttributeError: 'Figure' object has no attribute '_mpl_orig_savefig' #254

Open
ocehugo opened this issue Nov 12, 2024 · 3 comments
Labels
bug Something isn't working temporary fix available There is a workaround available until a proper fix is released
Milestone

Comments

@ocehugo
Copy link

ocehugo commented Nov 12, 2024

I just deployed a new environment; the most recent EOmaps 8.3.1 broke savefig, whereas 8.2 works.

Describe the bug
I can't save a _maps_base class figure.

To Reproduce

from eomaps import Maps
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

fig = plt.figure()
m = Maps(ccrs.PlateCarree(),f=fig)
m.savefig('test.png')
AttributeError: 'Figure' object has no attribute '_mpl_orig_savefig'

Expected behavior
Figure is saved.

General information:
python = 3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 16:05:46) [GCC 13.3.0]
EOmaps = 8.3.

A quick fix :

            if '_mpl_orig_savefig' in dir(self.f):
                self.f._mpl_orig_savefig(*args, **kwargs)
            else:
                self.f.savefig(*args,**kwargs)

It seems to work, but it may have side effects that I'm not aware of yet.

@ocehugo ocehugo added the bug Something isn't working label Nov 12, 2024
@raphaelquast
Copy link
Owner

raphaelquast commented Nov 12, 2024

Hey @ocehugo, thanks for reporting the issue!

There seems to be a problem if an explicit Figure object is passed to the initialization of the Maps object
(which is possible, but 99% of the cases not necessary)

Is there a particular reason why you want to pass an explicit Figure object to the initialization of the map?

In general, if you initialize the map without a dedicated figure, all works as expected:

m = Maps()
m.savefig("test.png")

You can then always access the underlying Figure object via m.f

@raphaelquast raphaelquast added this to the v8.3.2 milestone Nov 12, 2024
@ocehugo
Copy link
Author

ocehugo commented Nov 13, 2024

Is there a particular reason why you want to pass an explicit Figure object to the initialization of the map?

Because i declare a custom figure first (e.g. size) instead of modifying a fig postfacto, which is more verbose than passing the object rightly configured. Also, mpl habit...

@raphaelquast
Copy link
Owner

@ocehugo
OK, in this case, did you know that any additional keyword-argument passed to the initialization of the Maps object is forwarded to the initialization of the underlying figure (e.g. plt.figure())?

So this means you can save yourself 2 lines of code and directly do:

from eomaps import Maps
m = Maps(crs=3057, figsize=(10, 5))

(... and just to be clear... this is a valid bug and will be fixed in the next release! :-)

@raphaelquast raphaelquast added the temporary fix available There is a workaround available until a proper fix is released label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working temporary fix available There is a workaround available until a proper fix is released
Projects
None yet
Development

No branches or pull requests

2 participants