我正在用python geopandas为欧洲地图编写代码。
我目前正面临法属圭亚那的问题。我不想把它显示在地图上,但是,我找不到把它从法国分离出来的方法。
这是我的代码:
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
europe = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
europe = europe[europe.continent == 'Europe']
#europe = europe[europe.name != 'France']
data = pd.read_csv('HICP_EU_bycountry_12_2022.csv', delimiter=';')
data = data[['Area', 'Rate']]
merged_data = europe.merge(data, left_on='name', right_on='Area', how='left')
fig, ax = plt.subplots(figsize=(10, 6))
merged_data.plot(column='Rate', cmap='Reds', linewidth=0.8, ax=ax, edgecolor='0.8', legend=True)
ax.set_title('Inflation Rates in Europe', fontsize=16)
ax.set_axis_off()
for idx, row in merged_data.iterrows():
rate = row['Rate']
if not pd.isna(rate):
ax.annotate(text=str(rate), xy=row['geometry'].centroid.coords[0], horizontalalignment='center', fontsize=8)
ax.set_facecolor('#f7f7f7')
plt.show()