Ich folge diesem Beispiel, Python Mapping in Matplotlib Cartopy Color One Country. Es funktioniert voll mit mehreren Ländern, z. USA, Frankreich, Großbritannien, Japan.Cartopy-Python-Syntax - mehrere Objekte/Länder in einer Zeile
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'])
Ich würde gerne eine Liste von Ländern in einer Zeile setzen, anstatt die Aussagen immer und immer wieder zu wiederholen.
Ich habe versucht:
if country.attributes['adm0_a3'] == ['USA', 'FRA', 'GBR', 'JPN']:
Und any('USA, 'FRA', 'GBR', 'JPN')
Und ['USA or 'FRA' or 'GBR' or'JPN']
Und ein dict:
myDict = {'USA', 'FRA', 'GBR', 'JPN'}
if country.attributes['adm0_a3'] == myDict:
Natürlich, ich bin nicht die Logik ganz richtig hinzubekommen.
Mehrere Stunden Schmerzen für zwei Buchstaben! :Oh, danke. –