-
Notifications
You must be signed in to change notification settings - Fork 367
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
Colouring countries #1303
Comments
I'm not sure if this is helpful, but I just updated cartopy and I wasn't able to replicate the issue on my computer (Mac, cartopy v0.17.0, matplotlib v3.0.2). So it might be an issue that's more specific to your system (Windows OS or your environment). import matplotlib.pyplot as plt
import cartopy.io.shapereader as shpreader
import cartopy.crs as ccrs
import cartopy.feature as cfeature
%matplotlib inline
def area(ax, iso, clr) :
shp = shpreader.natural_earth(resolution='10m',category='cultural',
name='admin_0_countries')
reader = shpreader.Reader(shp)
for n in reader.records() :
if n.attributes['ADM0_A3'] == iso:
ax.add_geometries(n.geometry, ccrs.PlateCarree(), facecolor=clr,
alpha = 1.00, linewidth =0.15, edgecolor = "black",
label=n.attributes['ADM0_A3'])
return ax
iso3 = ['USA','CAN','RUS','GBR','ISL','FRA','ITA','CHN','AUT']
ax = plt.axes(projection=ccrs.Miller())
ax.add_feature(cfeature.COASTLINE)
for n in iso3 :
area(ax, n, "red")
plt.show() |
I get the same
and also with an update to:
|
I downgraded to cartopy 0.16 (which also downgraded associated packages as follows) and in doing so am able to iterate through the shpreader records Here are the relevant package versions associated with the downgrade:
|
I had the same issue with cartopy 0.17 and matplotlib 3.0.2 . I ended up downgrading to 0.16 (and upgrading matplotlib to 3.1.0). This fixed the error. I'm running the code in Atom with Hydrogen on a Mac. |
I think the real problem here is that you're passing in a single geometry to the plot, which can't be iterated upon. If you change your code to put the single geometry in a list
it works for me without errors. An unfortunate pluralization of geometries() requiring an iterable I suppose. |
Thank you so much @greglucas! That solves the problem I was having with the code. |
This thread is probably not the most descriptively names to deal with this issue, but it does seem that allowing add_geometeries() to plot non-iterable (single) objects makes sense. |
Glad that helped! I agree with you that it would be nice to not force plural here. My guess is something like: if isinstance(geometries, sgeom.base.BaseGeometry, sgeom.base.BaseMultipartGeometry)):
geometries = [geometries] near here: cartopy/lib/cartopy/feature/__init__.py Line 221 in de1cd82
would do the trick. But that is untested. Feel free to open a PR if you'd like! |
Description
Cartopy stop working when you try to color some countries, like Austria (AUT), Albania among others in Europe as far as I could see. My maps heve been working fine until couple last update on april.
Code to reproduce
Traceback
Full environment definition
Operating system
Windows 10
Cartopy version
0.17.0
conda list
4.64.14
pip list
19.1
The text was updated successfully, but these errors were encountered: