cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Instantiating from class cartopy.mpl.geoaxes.GeoAxes(*args, **kwargs)[source]

Open hklaufus opened this issue 3 years ago • 2 comments

Description

Using vAxes = cartopy.mpl.geoaxes.GeoAxes(projection=ccrs.Mercator())

throws KeyError:

File "/usr/lib64/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 410, in __init__
self.projection = kwargs.pop('map_projection')
KeyError: 'map_projection'

Note that the following does work:

vAxes = matplotlib.pyplot.axes(projection=ccrs.Mercator())

Although this throws a warning QSocketNotifier: Can only be used with threads started with QThread - which is a different issue?

Code to reproduce

import cartopy.crs as ccrs
import cartopy.mpl.geoaxes as cga
import cartopy.feature as cfeature

vAxes = cga.GeoAxes(projection=ccrs.Mercator())

Traceback

File "/usr/lib64/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 410, in __init__
self.projection = kwargs.pop('map_projection')
KeyError: 'map_projection'
Full environment definition

Operating system

Fedora 35

Cartopy version

0.20.1

hklaufus avatar Jan 03 '22 21:01 hklaufus

I have run into the same issue before and I wonder if there is a good reason why there is a "map_projection" keyword here rather than just using "projection" and validating that it is a valid instance of Projection or something similar.

It also lists this as an "optional" keyword, but as this error shows, it isn't so optional ;) https://github.com/SciTools/cartopy/blob/591fb5450e11b42b6de1cebe4f240112f915bd52/lib/cartopy/mpl/geoaxes.py#L400-L403

greglucas avatar Jan 04 '22 14:01 greglucas

Thanks for your support, @greglucas .

hklaufus avatar Jan 09 '22 11:01 hklaufus