Cartopy-Python syntax - multiple objects/countries in one line -
i'm following example, python mapping in matplotlib cartopy color 1 country. it's working several countries, e.g. usa, france, uk, japan.
for country in countries: if country.attributes['adm0_a3'] == 'usa': ax.add_geometries(country.geometry, ccrs.platecarree(), facecolor='#008744', alpha = 0.5, label=country.attributes['adm0_a3']), if country.attributes['adm0_a3'] == 'fra': ax.add_geometries(country.geometry, ccrs.platecarree(), facecolor='#008744', alpha = 0.5, label=country.attributes['adm0_a3']), + 'gbr' + 'jpn' else: ax.add_geometries(country.geometry, ccrs.platecarree(), facecolor=('#c4e6ff'), label=country.attributes['adm0_a3'])
i'd put list of countries in 1 line rather repeating statements on , over.
i tried:
if country.attributes['adm0_a3'] == ['usa', 'fra', 'gbr', 'jpn']:
and any('usa, 'fra', 'gbr', 'jpn')
and ['usa or 'fra' or 'gbr' or'jpn']
and dict:
mydict = {'usa', 'fra', 'gbr', 'jpn'} if country.attributes['adm0_a3'] == mydict:
obviously, i'm not getting logic quite right.
you should use in
keyword, this:
for country in countries: if country.attributes['adm0_a3'] in ['usa', 'fra', 'gbr', 'jpn']: ax.add_geometries(country.geometry, ccrs.platecarree(), facecolor=(0, 0, 1), label=country.attributes['adm0_a3']) else: ax.add_geometries(country.geometry, ccrs.platecarree(), facecolor=('#c4e6ff'), label=country.attributes['adm0_a3'])
is looking for?
Comments
Post a Comment