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

Replace _autoscaleX_on with get_autoscalex_on() in GeoAxes #2054

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

holzschu
Copy link

Rationale

Modern implementations of matplotlib have removed the variables _autoscaleXon and _autoscaleYon.
mpl/geoaxes.py references these variables, resulting in an error when running cartopy:

AttributeError: 'GeoAxesSubplot' object has no attribute '_autoscaleXon'

This PR replaces the deprecated variables with the functions get_autoscalex_on() (and set_autoscalex_on()), that are present in matplotlib.

Implications

As far as I can tell, the change was introduced with matplotlib version 3.5.2, released May 3rd, 2022.
Based on what I can see from the matplotlib github site, the change should be compatible with previous versions of matplotlib.

@SciTools-assistant SciTools-assistant added the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Jun 26, 2022
Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good! Test failures seem unrelated since I see the same in #2056.

@greglucas
Copy link
Contributor

@holzschu , it looks like you still need to sign the CLA: Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form

@greglucas greglucas closed this Jun 28, 2022
@greglucas greglucas reopened this Jun 28, 2022
@holzschu
Copy link
Author

Thanks for the explanation. I have signed the CLA.

@greglucas greglucas removed the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Jun 28, 2022
@SciTools-assistant SciTools-assistant added the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Jun 28, 2022
@greglucas greglucas merged commit f69a228 into SciTools:main Jun 28, 2022
@greglucas greglucas removed the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Jun 28, 2022
@QuLogic
Copy link
Member

QuLogic commented Aug 20, 2022

Unfortunate this wasn't backported to 0.20.3

@QuLogic QuLogic added this to the 0.20.4 milestone Aug 20, 2022
@greglucas
Copy link
Contributor

We could cut a 0.21.0 release from main... It looks like it has been about a year since 0.20.0 was released.

@dopplershift
Copy link
Contributor

dopplershift commented Aug 22, 2022

I don't have a preference, but we need to release something before Matplotlib releases 3.6 with both this and #2071.

@ElmWer
Copy link

ElmWer commented Sep 17, 2022

since matplotlib is updated to 3.6 I get the following error

AttributeError: 'GeoAxesSubplot' object has no attribute '_autoscaleXon'

packages

cartopy 0.20.2
matplotlib-base 3.6.0

code
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mollweide(central_longitude=0))
ax.stock_img()

Traceback
/tmp/ipykernel_10883/381787420.py in <cell line: 7>()
5 ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mollweide(central_longitude=0))
6 ax.set_global()
----> 7 ax.stock_img()

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in stock_img(self, name)
1062 '50-natural-earth-1-downsampled.png')
1063
-> 1064 return self.imshow(imread(fname), origin='upper',
1065 transform=source_proj,
1066 extent=[-180, 180, -90, 90])

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in wrapper(self, *args, **kwargs)
316
317 kwargs['transform'] = transform
--> 318 return func(self, *args, **kwargs)
319 return wrapper
320

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in imshow(self, img, *args, **kwargs)
1366 'handle a %s in imshow.' % type(transform))
1367
-> 1368 target_extent = self.get_extent(self.projection)
1369 regrid_shape = kwargs.pop('regrid_shape', 750)
1370 regrid_shape = self._regrid_shape_aspect(regrid_shape,

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in get_extent(self, crs)
812
813 """
--> 814 p = self._get_extent_geom(crs)
815 r = p.bounds
816 x1, y1, x2, y2 = r

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in _get_extent_geom(self, crs)
819 def _get_extent_geom(self, crs=None):
820 # Perform the calculations for get_extent(), which just repackages it.
--> 821 with self.hold_limits():
822 if self.get_autoscale_on():
823 self.autoscale_view()

~/miniconda3/lib/python3.9/contextlib.py in enter(self)
117 del self.args, self.kwds, self.func
118 try:
--> 119 return next(self.gen)
120 except StopIteration:
121 raise RuntimeError("generator didn't yield") from None

~/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in hold_limits(self, hold)
489 view_lim = self.viewLim.frozen().get_points()
490 other = (self.ignore_existing_data_limits,
--> 491 self._autoscaleXon, self._autoscaleYon)
492 try:
493 yield

AttributeError: 'GeoAxesSubplot' object has no attribute '_autoscaleXon'

@greglucas
Copy link
Contributor

@ElmWer, you'll have to upgrade to Cartopy v0.21 to work with Matplotlib 3.6.

zmoon added a commit to knubez/TAMS that referenced this pull request Oct 30, 2022
SciTools/cartopy#2054

CI failed for commit 50cd733
because the env got mpl 3.6.1 but cartopy 0.20.2
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 this pull request may close these issues.

7 participants